Ask HN: Automatically download and reference external website scripts?

2 points by kekebo ↗ HN
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 ] thread
Hi

are 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

that's a great idea, thanks!
You're looking for Bower: http://bower.io

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?)

Perfect!

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).

When you use a CDN, you can use a local fallback. Note that very old/shitty browsers won't support scheme-less URLs or jQuery 2.x, although those options are more modern and preferable. You just have to make the decision based on your users.

Here's example code for local jQuery fallback:

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="js/jquery-2.1.3.min.js">\x3C/script>')</script>
You can also use yepnope, but I don't use that personally.