[whatwg] Script preloading

Ryosuke Niwa rniwa at apple.com
Thu Aug 29 16:34:34 PDT 2013

On Aug 29, 2013, at 8:37 AM, Nicholas Zakas <standards at nczconsulting.com> wrote:

> When Kyle and I originally started pushing for a way to preload JavaScript many moons ago, the intent was very simple: to allow the downloading of JavaScript and execution of JavaScript to be separate. The idea being that you should be able to preload scripts that you'll need later without incurring the cost of parsing and execution at that point in time. There are many examples of people doing this, the most famous being the Gmail mobile approach of loading JavaScript in comments and then pulling that code out and eval()ing it.
> I still feel very strongly that this pattern is a necessary evolution of how we should be able to load scripts into web pages. I just want a flag that says "don't execute this now" and a method to say "okay, execute this now". Allowing that flag to be set both in HTML and JavaScript is ideal.
> The question of dependency management is, in my mind, a separate issue and one that doesn't belong in this layer of the web platform. HTML isn't the right spot for a dependency tree to be defined for scripts (or anything else). To me, that is a problem to be solved within the ECMAScript world much the way CSS has @import available from within CSS code. 

But why do you want an ability to say "don't execute this now" if there were no dependencies?  Loading an extra script file that's not needed immediately can add few hundred of milliseconds to the total page load time over a slow network connection.

To put it another way, I don't see why anyone wants to load a script and not execute it other than for the purpose of avoiding the network request at a later time.  However, if that were the main purpose of providing such a functionality, then we also need to address the issue of this load request needing to have a lower priority than other load requests that are vital for the page.  In fact, we might want to avoid sending the request of a script file altogether if the user isn't going to interact the parts of the page that needs such a script.

- R. Niwa

More information about the whatwg mailing list