Cache script syn or asyn?

Hi,
I’ve a doubt
First of all I know that’s the asyn way no freeze the browser :slight_smile:
what’s the best way for include script in a page
for caching purpose syn or asyn ?
syn


<script src="//connect.facebook.net/en_US/all.js"></script>

asyn


(function(d){
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement('script');js.id = id;js.async = true;
    js.src = '//connect.facebook.net/en_US/all.js';
    ref.parentNode.insertBefore(js, ref);
}(document));

I think it’s quite irrelevant but …
Thanks in advance

The async attribute instructs browsers that understand it to proceed downloading the rest of the page and scripts while it’s loading that script.
It looks to have pretty complete support these days.

I think you can always add it safely if the scripts aren’t dependent on one another.
I don’t believe there’s a difference between adding the async attribute to a tag or adding the script dynamically like in your example.

I’ve never bothered worrying about micro optimisations like these.
My scripts are always 1 or two scripts at the bottom so there’s little need to download other things asynchronously.


<script src="my-minified-compressed-js.js"></script>
<script src="facebook.js"></script>
<script src="google-analytics.js"></script>