W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2014

Re: [whatwg] Preloading and deferred loading of scripts and other resources

From: Ilya Grigorik <igrigorik@gmail.com>
Date: Mon, 8 Sep 2014 17:31:03 -0700
Message-ID: <CAKRe7JHuzjysqFo-JRXx=epBs7zBGZKzt8DTidDj_PNWro9PCw@mail.gmail.com>
To: Ian Hickson <ian@hixie.ch>
Cc: whatwg <whatwg@lists.whatwg.org>
On Mon, Sep 8, 2014 at 1:33 PM, Ian Hickson <ian@hixie.ch> wrote:

> > I really like your proposal for "as="... Concretely it could look
> something
> > like this:
> >
> > <link rel="preload"
> >         href="/some/asset.css"
> >         as="stylesheet"    (used to initialize default priority, headers,
> > etc)
> >         load-settings="{}"  (JSON payload with custom headers, priority
> > [2], etc)
> >         media= "..."          (relevant media queries..)
> >         probability=""        ([0.0-1.0] used for speculative fetches
> [3])
> > >
>
> I don't understand why this would be better than:
>
>    <link rel=stylesheet loadpolicy="declare" href="/some/asset.ass"
>          loadsettings="..." media="...">


Better or worse is not the point. I think the current proposal fails to
address the larger underlying problem.

The platform is missing a lower-level primitive (declarative and
imperative) that is able to explain resource loading with the same
expressive power as requests initiated by the browser itself. XHR provides
arbitrary resource loading, but it lacks the power to express
transport-layer options such as relative request priority and dependencies,
and it also hides requests from the preload scanner, which is a deal-break
for performance. To address this, we need two things:

(1) Fetch API with "load-settings" addresses the imperative side of the
problem.
(2) We also need a declarative, content-type agnostic primitive to express
resource loads, such that the preload scanner is able to pickup and
processes these fetches on par with all other resources -- hence my
rel=preload suggestion [1].

We can augment img, script, and other elements, with load-settings and
other flags, but that still doesn't cover all the necessary cases. For
example, how do I fetch a font file, or an arbitrary JSON payload with
app-data, etc? Note that I'm looking for declarative syntax that allows me
to set arbitrary fetch priorities - e.g. upgrade my JSON payload to high
priority because I need it to render content on the screen. This is the
part that we *need* to solve.

Once we have the low-level declarative+imperative primitives for loading
resources, we can build up all other loading and dependency patterns in
app-space. The loadpolicy/needs attributes are syntax sugar for select
resource types -- nice, but (IMO) not strictly necessary and not sufficient
for the more general case of content-types not covered by dedicated
elements.

ig

[1] https://igrigorik.github.io/resource-hints/#preload
Received on Tuesday, 9 September 2014 00:32:09 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:23 UTC