reinitializer.js/README.md

23 lines
1.0 KiB
Markdown
Raw Normal View History

2023-10-02 19:12:21 +07:00
# reinitializer.js
2023-10-02 18:51:40 +07:00
2023-10-02 19:11:20 +07:00
A library for tracking and reinitializing `<link>` and `<script>` elements so that the browser downloads them.
2023-10-02 18:53:45 +07:00
2023-10-02 19:11:20 +07:00
Used when developing any dynamic requests via JS where links to third-party documents are supplied along with HTML content.
# Instruction
By default, the library is observe the first `<main>` element, but you can reassign it by passing an argument of type `{HTMLElement|null}` to `new e.detail.reinitializer();`
2023-10-06 19:27:47 +07:00
document.addEventListener('reinitializer.initialized', function (e) {
// Initialized reinitializer
// Initialize of instance of reinitializer
const reinitializer = new e.detail.reinitializer();
// First reinitialization with prevented downloading
reinitializer.handle(false);
// Start observation
reinitializer.start();
});
2023-10-02 19:11:20 +07:00
By default, after reinitialization, `<link>` elements are moved to the end of the `<head>` element, and `<script>` elements are moved to the end of the `<body>` element. You can override this behavior by changing the `reinitializer.js` and `reinitializer.css` properties.