W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2013

Re: [whatwg] Script preloading

From: Ryosuke Niwa <rniwa@apple.com>
Date: Thu, 29 Aug 2013 16:34:34 -0700
Message-id: <6CBABF60-AEA8-4E8A-A9B6-1879FAE4E0AE@apple.com>
To: Nicholas Zakas <standards@nczconsulting.com>
Cc: Brian Kardell <bkardell@gmail.com>, whatwg@whatwg.org, Jonas Sicking <jonas@sicking.cc>
On Aug 29, 2013, at 8:37 AM, Nicholas Zakas <standards@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
Received on Thursday, 29 August 2013 23:35:06 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:23 UTC