[whatwg] Link.onload

Garrett Smith dhtmlkitchen at gmail.com
Sat Mar 14 14:46:37 PDT 2009


On Sat, Mar 14, 2009 at 1:48 PM, Greg Houston <gregory.houston at gmail.com> wrote:
> This is a request for the link element to be given an onload attribute.
>

I see.

> Often when lazy loading a plugin into an web app it is necessary for
> the plugin's stylesheets to be applied before the plugin's JavaScript
> is downloaded. Without the link element having an onload event there
> is not really a straightforward way of doing this.
>

It sounds like you want to load resource with dependencies.

> Currently I am using XMLHttpRequests to grab the stylesheets first
> since XHR has a success callback, and then appending the stylesheets
> to the document.head relying on the browser using the cached
> stylesheet. This seems to work for the most part, but really there are
> no guarantees.

When a stylesheet is added to the document, how (or even if) the
resource is downloaded and applied is not part of any official
standard.

>
> There are other odd workarounds but none of them as straightforward,
> elegant, and easy to use as the link elements simply having an onload
> attribute.
>

I proposed a solution to a similar problem not too long ago.

<script depends="[idref]" ...></script>

This would allow for scripts to run without having to wait for
stylesheets to load. When the browser parses <script depends="...", it
looks for elements matching ids in the depends attribute and downloads
all of them before running the script.

This could be used for other resources, too.

<object depends="[idref]">
...
</object>

- where [idref] is the stylesheet to be loaded.

> Thank you for your consideration.
>

You seem optimistic.

Check the thread: "[whatwg] defer on style, depends"

http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-February/018420.html

The first sentence:-
| This is a request for the link element to be given an onload attribute.

Example:-
<link onload="loadPlayer()" ...>

- would solve your problem, but with less simplicity than the
depends="[...]" would.

> Greg Houston
>

Garrett


More information about the whatwg mailing list