Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The main reason you should do this is not so much as a CDN fall-back, but to prevent users from downloading redundant files retrieved from other sites.

Also remember to always use the https URL for the assets, whenever able.



Is there a reason to use https over a protocol-relative url? My go-to is <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>


No, protocol-relative is the way to go.


I think HTTPS isn't a bad idea. You don't want some MITM messing with your 3rd-party JS.


If you're loading your 3rd-party JS from an HTTP page, they already can.


Sure, but it's one less avenue for a MITM attack.


Not directly affecting jQuery/JavaScript, but when you use protocol relative URL all over the places, you need to be careful as Internet Explorer 7 & 8 will download stylesheets twice if the http(s) protocol is missing: http://www.stevesouders.com/blog/2010/02/10/5a-missing-schem...


Some older versions of IE don't like protocol-relative, IIRC. Depends on your target platform, and customer-base.


I've tested the protocol-relative URL in every version of IE that was available on Browsershots about a year ago (which went back even further than IE6, IIRC). None of them had trouble with it.


I remember suggesting it to someone else at my previous employer and there were issues. It may have been Outlook[1] though. I can't recall off-hand.

[1] http://stackoverflow.com/questions/4303633/preventing-secure...


To clarify, IE6 and before. If you're target market doesn't include IE6, protocol-relative URLs work just fine.


Isn't using already cached assets one of the reasons to use a CDN for popular scripts?


Except that the chance of the asset you are requesting being cached is pretty minimal. See https://github.com/h5bp/html5-boilerplate/pull/1327 for links and discussion about this. The conclusion seemed to be that is it likely that a CDN does provide some benefit, but more from a localization of content and offloading the bandwidth, rather than a speed or cache hit benefit.


I might be missing something, but that link really only talks about the potential benefit of a file already being cached locally on the end-user's device.

There's still a significant benefit in just storing the file closer to the end-user, rather than in a single central location, as the CDN is likely to have both lower latency and have higher bandwidth than the source website.

Now, if your file was so unique and rarely accessed that it wouldn't even be cached on the CDN, then I'd agree with those findings.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: