https://github.com/webreflection/domcontentloaded
fixing the (in)famous event that does not trigger once "loaded"
https://github.com/webreflection/domcontentloaded
Last synced: over 1 year ago
JSON representation
fixing the (in)famous event that does not trigger once "loaded"
- Host: GitHub
- URL: https://github.com/webreflection/domcontentloaded
- Owner: WebReflection
- Created: 2014-02-20T04:35:49.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-10T17:18:43.000Z (about 12 years ago)
- Last Synced: 2024-12-24T03:11:53.697Z (over 1 year ago)
- Language: JavaScript
- Size: 243 KB
- Stars: 31
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
DOMContentLoaded
================
fixing the (in)famous event that does not trigger once "loaded".
Please [read the post](http://webreflection.blogspot.com/2014/02/the-underestimated-problem-about-script.html) to know more about issues you might have relying this event.
### How To
Simply include [the inline version of the script](./dcl.js) on top of any of your HTML pages (few extra bytes, really nothing to worry about) and stop worrying about not being initialized once the **DOM Content** ... has been **Loaded** !!!
Can you believe it ?
### Content Security Policy
If you are under this restriction, here the deprecated `sha1` version of [the script](./dcl.js): `sha1-//cbZaIlYySeh0GGSwpZKzOAkvg=`
While if you are targeting modern browsers, here the `sha256` version: `sha256-XpSHSiwcWV9TTNd43i/nMFtZA8u8gQVfVXEy6Wa68a0=`
These digests have been tested without problems via server side headers, as well as meta tag:
```html
```
Bear in mind you must specify `'unsafe-inline'` in addition to `'self'` for backward compatibility.
### Example
Just try to write something like:
```javascript
document.addEventListener('DOMContentLoaded', function (e) {
alert([e.type, e.currentTarget === document]);
});
```
in [this page console](http://webreflection.github.io/DOMContentLoaded/example.html) and you should have your _always notified_ `DOMContentLoaded` event.