Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event which triggers before DOMContentLoaded

In my Firefox extension I am using DOMContentLoaded to detect page load and insert my HTML. Is there an event which triggers before this and still the document is available at that time?

like image 593
Selvaraj M A Avatar asked Oct 12 '11 19:10

Selvaraj M A


People also ask

What is the DOMContentLoaded event?

The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading. A different event, load , should be used only to detect a fully-loaded page.

How do I know if I am DOMContentLoaded?

If you want to know "exactly" if DOMContentLoaded was fired, you could use a boolean flag like this: var loaded=false; document. addEventListener('DOMContentLoaded',function(){ loaded=true; ... }

What is difference between load and DOMContentLoaded event?

The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images. This is in contrast to DOMContentLoaded , which is fired as soon as the page DOM has been loaded, without waiting for resources to finish loading.

Does DOMContentLoaded wait for CSS?

DOMContentLoaded does not wait for stylesheets to load, however deferred scripts do wait for stylesheets, and DOMContentLoaded queues behind deferred scripts. Also, scripts which aren't deferred or async (e.g. <script> ) will wait for already-parsed stylesheets to load.


1 Answers

Note: This answer refers to XUL-based extensions. As of Firefox 57, this technology is obsolete. The functionality mentioned here is no longer available to extensions.

There is content-document-global-created notification that is sent out when a document is created, before any content is added to it (to be precise, it happens when the browser receives the HTTP headers of the response and knows that it isn't a redirect or such). That's the earliest point where you can get the document. The DOMContentLoaded event is fired once Gecko finishes downloading the contents of the document, that's the earlies point where you can access the complete DOM. In between there is a bunch of other events, e.g. lots of progress listener events - which one you use depends on what you are trying to do, there is no general answer.

like image 166
Wladimir Palant Avatar answered Sep 28 '22 12:09

Wladimir Palant