Ask HN: Automatically download and reference external website scripts?
Dear HNers,
I'm trying automate downloading the latest versions of all external scripts (jquery, prototype etc.) on our website and load them locally in order to improve page load times.
Writing a script like that seems fairly easy but just wondering if there's a well built solution out there.
5 comments
[ 2.8 ms ] story [ 21.2 ms ] threadare you using git version control? so you could hook in the needed libraries as submodules. that would keep them updated and you just have to commit the changes once to have it locally accessible.
best regards
For single-file libs like jQuery, you should look at using a CDN. I believe Google's jQuery CDN is the fastest. There's no need to host it yourself.
Semi-related: having both jQuery and Prototype on a single page is going to hurt load times. See if you can replace all your Prototype stuff with jQuery.
(Just out of curiosity, why exactly are you using Prototype at all?)
Considering loading scripts from CDN: I just like to keep as much as possible locally and minimizing having to rely on things I have no control over (I've noticed Google Fonts taking up to almost a second in a few rare cases).
As for why I'm (still) using prototype: I'm taking over a (mediocrely designed) magento shop, which has prototype as a standard dependency (apparently for ECMA5 support).
Here's example code for local jQuery fallback:
You can also use yepnope, but I don't use that personally.