Would async script loaders like LABjs or $script.js prove beneficial, neutral, or negative if already using a CDN supporting SPDY?
- I'm going to use a full-site CDN with SPDY, for example Cloudflare
- I've read Script-injected "async scripts" considered harmful but thanks to jQuery dependencies I need to control execution order.
- I want to keep dependencies as unbundled as possible
i.e. I've got a series of JS scripts where <script src=
would work fine and <script async src=
would not. I don't want sync because it would be blocking. And defer
is too flaky to consider.
Given the above, I would use a script loader without second thought if it weren't for the uncertainty of SPDY. I probably just need to know whether the approach used by these scripts still gets the same SPDY benefits (pipelining, compression, etc) as "regular" approaches?
Another way of framing the question is: what would be the impact of switching from synchronous script loading with SPDY CDN to using async script loaders with SPDY CDN?
I've had very bad performance issues using Cloudflare as a SPDY proxy, and my benchmarks went from 1.5 seconds to about 4 seconds over SPDY (266% slower). You should test yourself, and you should see faster results with direct connections to your server.
CDN's would slow you down, because SPDY allows all resources to be pulled from one socket connection, and a CDN (https) would require multiple TLS handshakes and round-trip connections which could slow your site down.
This test shows about 350 resources loaded via SPDY, and you won't get those results with a CDN: http://httpvshttps.com/
Here's an interesting article:
https://thethemefoundry.com/blog/why-we-dont-use-a-cdn-spdy-ssl/