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

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


<link rel="stylesheet" href="//" type="text/css">
<link rel="stylesheet" href="//" 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 *