HTTP/HTTPS 的相對路徑

寫網頁很常看到 http://www.example.com/static/foo.jpg 這種用法,或是 /static/foo.jpg 這種用法。前者的用法在 HTTPS 的環境下會產生問題 (在 HTTPS 裡讀取 HTTP object),後者的用法只能在同一台機器上。

如果想要保持 Protocol,但卻是不同機器時,可以用 //www.example.com/static/foo.jpg 這種用法。即使都是 HTTP 或 HTTPS 也有好處:少送出 5 bytes 或 6 bytes。

這次改版裡面用了很多,像是這樣:

<link rel="stylesheet" href="//s.pixfs.net/blog.pixnet.net/comment-form.css?v=e86de92d69f3b8eba3448c5404551725" type="text/css">
<link rel="stylesheet" href="//s.pixfs.net/blog.pixnet.net/choc-base.css?v=e86de92d69f3b8eba3448c5404551725" type="text/css">

這是之前看到的技巧,剛剛找到看到的地方了:Http-https transitions and relative URLs

This entry was posted in Computer, Murmuring, Network, WWW. Bookmark the permalink.

One Response to HTTP/HTTPS 的相對路徑

  1. Pingback: LinmiC SOuL» Blog Archive » Http/Https transitions and relative URLs

Leave a Reply

Your email address will not be published. Required fields are marked *