Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of CDN content served via https over http

Tags:

google-cdn

All of google's CDN libraries are served via https. Is there any advantage of serving them via https over http ?

like image 255
anjanesh Avatar asked Dec 02 '22 04:12

anjanesh


1 Answers

cdhowie is correct. If your page is served via http, then serving the library via https merely adds a small amount of overhead. If your page is served via https, then serving the library via http would be a potential security hazard, and most browsers will issue a warning. So https is given as the default option.

See this related question: HTTPS and external (CDN) hosted files?

But you can have the best of both worlds by omitting the protocol entirely, e.g.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

That tells the browser to automatically use the same protocol that was used to serve the page. Little-known trick, but widely supported. More info here: Is it valid to replace http:// with // in a <script src="http://...">?

like image 148
Trevor Burnham Avatar answered Jan 25 '23 22:01

Trevor Burnham