Protocol-relative_URL - http: 나 https: 지정이 없이 // 로 시작하는 URL 에 대해서 > 개발

본문 바로가기
사이트 내 전체검색

개발

Protocol-relative_URL - http: 나 https: 지정이 없이 // 로 시작하는 URL 에 대해서

페이지 정보

profile_image
작성자 관리자 (112.♡.173.204)
댓글 0건 조회 2,792회 작성일 21-05-11 16:51

본문

## 개요

html 에서 a 태그에 링크를 걸때 등에서 프로토콜을 지정하지 않으면, 자동으로 현재의 http 와 https 상태에 따라 링크가 결린다.
이를 Protocol relative URL 이라고 한다.

아래와 같이 원격 cdn 의 js 파일을 링크 걸때도 많이 사용한다.
```
<script type="text/javascript" src="https://cdn.example.com/js_file.js"></script>
<script type="text/javascript" src="//cdn.example.com/js_file.js"></script>
```
https://stackoverflow.com/questions/550038/is-it-valid-to-replace-http-with-in-a-script-src-http


## 결론

결론부터 얘기하면,
https:// 를 명시적으로 붙여 주는 것이 좋다.

틀렸다는 것이 아니고, https:// 가 가능하다면 붙여 주는 것이 권장된다.

예전(2010년대 초반)에는 http 가 일반적이고 https 가 선택적이었던 시절이었다.
하지만, 지금은 SSL 즉 https 가 일반화가 되었다.
이에 https:// 를 명시적으로 붙여 주는 것이 좋다고 한다.
오류를 발생시킬 가능성을 줄일수 있다는 얘기도 있다.

그 예로, 구글에서 배포하는 cdn 서비스의 js 파일들의 링크가 예전에는 // 로 시작하는 링크였는데,
지금은 https:// 로 시작하는 링크들로 모두 변경되었다.


## Wikipedia 의 Status

In June 2015, Wikipedia did a "hard enable" of HTTPS meaning the site is 100% HTTPS. Because protocol relative is relative to the site where the URL is linked from, all protocol relative URLs on Wikipedia will render as HTTPS.

This means protocol relative links should no longer be used on Wikipedia, and existing protocol relative links should be converted to either the HTTP or HTTPS scheme. Existing protocol relative links where the underlying is http will break. For example this doesn't work:

[1] (//americanbilliardclub.com/about/history/)
But this does:

[2] (http://americanbilliardclub.com/about/history/)



## 참고
https://stackoverflow.com/questions/550038/is-it-valid-to-replace-http-with-in-a-script-src-http
https://stackoverflow.com/questions/11881054/is-a-url-starting-with-valid
https://en.wikipedia.org/wiki/Wikipedia:Protocol-relative_URL

추천0

댓글목록

등록된 댓글이 없습니다.

Total 386건 4 페이지
  • RSS
개발 목록
번호 제목 조회 추천 날짜
3262573005-14
열람중2793005-11
3243593005-10
3232745005-08
3224494005-07
3212948005-07
3202590005-06
3197011005-06
3183098005-04
3173769005-04
3161687005-04
3151632005-04
3143158005-04
3131857005-02
3123163005-01
3112101005-01
3102029005-01
3092778004-30
3081841004-30
3073454004-30

검색


사이트 정보

Copyright © Baragi.Net. All rights reserved.