作者hijkxyzuw (i,j,k) ×(x,y,z)
看板Web_Design
標題[問題] 使用 // 取代 http:// 或 https:// ?
時間Sat May 7 17:30:21 2016
在一些網站會看到用 // 開頭取代用 http:// 或 https:// 開頭。
像是 flickr 的內嵌分享連結就是用 //embedr.filckr.com/xxxx.js
google 也建議使用這樣的語法,原因是因為網站可能改用 http 或 https 。
https://google.github.io/styleguide/htmlcssguide.xml#Protocol
這種寫法的接受度如何?
我的 firefox 44 還 45 認不出來......,
會去找根目錄上的檔案;當然是找不到啦。
windows XP 上不再被支援的 chrome 也不支援。
====================================================
題外話,
其實是在查 URL 中用來指明協議開頭的雙斜線
有什麼意義時無意間看到的。
而伯納李 ( Berners-Lee ) 也為這件事公開道歉了 XD
http://www.sitepoint.com/sir-tim-berners-lee-http-slashes/
在這串 slackoverflow 有人引用了他的看法:
http://superuser.com/questions/465565/in-a-url-what-is-for
大意是雙斜線有引人注目的作用;
就像看到 @ 會直覺想到 email ,看到 // 會想到 URL 。
但單斜線也可以啊!
--
作者 sky226778 (青蛙呱呱呱) 看板 Gossiping
標題 [問卦] 碗粿和蘿蔔糕的差別
時間 Tue Oct 6 21:04:06 2015
→ r89556: 蘿蔔糕是用蘿蔔做的 碗糕是用碗做的 10/06 21:05
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.207.237
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Web_Design/M.1462613427.A.CCA.html
1F:→ jmlntw: 你是在本機上測試吧,那當然認不出來 05/07 17:36
意思是如果用了 file:// ,瀏覽器才會將她解析為相對路徑嗎?
※ 編輯: hijkxyzuw (140.116.207.237), 05/07/2016 17:43:30
2F:推 LPH66: 你把它理解成「對協議那一層的『相對』路徑」 05/07 17:46
3F:→ jmlntw: 省略的話瀏覽器會去找跟它來源一樣的 scheme, 05/07 17:47
4F:→ LPH66: 也就是說取代掉原網址 // 後的部份 05/07 17:47
5F:→ jmlntw: http 找 http、https 找 https、file:// 就找 file:// 05/07 17:47
兩位推文混在一起了 :目
大概是用了 file:// 就會把沒寫協議視為 file:// 。
而另一個使用雙斜線的理由就是避免和根目錄的單斜線搞混。
像 /path/to/file.js 和 //server.name/path/to/file.js
就是用雙斜線來區分是主機名或路徑名。
但使用 :/ 甚至是 : 也可以啊!就變成
:server.name/path/file.js 或 :/server.name/path/file.js 。
※ 編輯: hijkxyzuw (140.116.207.237), 05/07/2016 17:59:05
6F:→ ssccg: 你說的這兩個不可以,因為authority那段是optional的 05/07 22:08
7F:→ ssccg: scheme:[//[user:pwd@]host[:port]][/]path[?query][#frag] 05/07 22:09
8F:→ ssccg: 以你的寫法server.name也直接是path的一部分 05/07 22:09
9F:→ ssccg: 當然當初設計URI時可以不要設計成這樣,不要用// 05/07 22:12
10F:→ ssccg: 但是現況已經是這樣,要表達之後的部分是authority就必須// 05/07 22:13
11F:→ hijkxyzuw: 大概懂了。都忘了還有 port 和登入的欄位。 05/08 17:21