Skip to content

Commit 7141cd6

Browse files
committed
document dom ready optimization
1 parent 9b774d9 commit 7141cd6

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div align="center">
22
<h1>IMPORTED COMPONENT ✂</h1>
3+
<h2>Code splitting which always works<sup>*</sup></h2>
34
<br/>
45
<img src="./assets/imported-logo.png" alt="imported components" width="409" align="center">
56
<br/>
@@ -31,17 +32,20 @@
3132
<br/>
3233
</div>
3334

35+
> <sup>*</sup> It's really will never let you down. All credits to your bundler.
36+
3437
👉 [Usage](#usage) | [API](#api) | [Setup](#setup) | [SSR](#ssr) | [CCS](#css) [Concurrent loading](#concurrent-loading) | [Webpack/Parcel](#bundler-integration)
3538

3639

3740
Key features:
38-
- 1️⃣ Single source of truth - your __bundler drives__ everything.
41+
- 1️⃣ Single source of truth - your __bundler drives__ everything
3942
- 📖 __library__ level code __splitting__
4043
- 🧙️ Hybrid and __Prerendering__ compatible
4144
- 💡 __TypeScript__ bindings
4245
- ⚛️ __React.Lazy__ underneath (if hot module updates are disabled)
4346
- 🌟 Async on client, sync on server. Supports __Suspense__ (even on server side)
44-
- 📦 could work with __any bundler__ - webpack, rollup, parcel or puppeteer - it does not matter
47+
- 📦 could work with __any bundler__ - webpack, rollup, parcel or puppeteer - it does not matter
48+
- 🤹‍♂️ working as well with any `import` you may provide
4549

4650
Other features:
4751
- 🔥 Hot-Module-Replacement/React-Hot-Loader friendly
@@ -53,24 +57,24 @@ Key features:
5357
- 📦 and yes - this is the only __parcel-bundler compatible__ SSR-friendly React code splitting library
5458

5559
👍 Better than [React.Lazy](https://reactjs.org/docs/code-splitting.html#reactlazy):
56-
- It __IS__ Lazy, just with some stuff around*
57-
- SSR, Prerendering and Preloading support.
58-
- With or without Suspense, and easier Error cases support.
60+
- It __IS__ Lazy, just with some stuff around<sup>*</sup>
61+
- SSR, Prerendering and Preloading support
62+
- With or without Suspense, and easier Error cases support
5963

6064
👍 Better than others:
61-
- Not bound to webpack.
62-
- Easy way to use per-browser(modern/legacy) bundles.
63-
- Strong typing.
64-
- Prerendering support
65+
- Not bound to webpack
66+
- Easy way to use per-browser(modern/legacy) bundles - you down have to mess with actual browser support
67+
- Strong typing
68+
- Working with any imports, even native, external or derived ones.
6569

6670
👌 Client-side module resolution
6771
- Loads chunks only after the `main one`, as long as loader code is bundled inside the main chunk, so it should be loaded first.
6872
- Not an issue with the `progressive hydration`, and might provide a better UX via feature detection.
6973
- Provides 👨‍🔬 technological workaround - [see here](#concurrent-loading)
7074

7175
📦 Optional bundler integration for the best experience
72-
- prefetching backed by webpack stat.json and asset.json
73-
- parcel-manifest support
76+
- prefetching backed by webpack `stat.json` and `asset.json`
77+
- `parcel-manifest.json` support
7478

7579
👯‍♀️Works better in pair
7680
- [react-prerendered-component](https://github.com/theKashey/react-prerendered-component) for prerendering, partial hydration and react fragment caching
@@ -356,6 +360,27 @@ And let's call it - a __Scheduler optimization__. See __loading prediction__ sec
356360
```
357361
This will just start loading extra chunks before the main bundle got completely parsed and executed.
358362

363+
#### Defer till DOMReady
364+
> 💡 Another perfect option would be to wait till DomReady event.
365+
366+
```js
367+
// index.js (boot)
368+
import './src/imported'; // the file generated by "generate-imported-component" (.2)
369+
import {rehydrateMarks} from 'react-imported-component/boot';
370+
371+
rehydrateMarks(); // just start loading what's needed
372+
373+
374+
const startApp = () => require('./main'); // <--- your main scripts
375+
376+
// it's "not safe" to start you application before DOM is "ready"
377+
if (document.readyState === "loading") {
378+
document.addEventListener("DOMContentLoaded", startApp);
379+
} else {
380+
startApp();
381+
};
382+
```
383+
359384
#### Scheduler optimization + stream render
360385
> See examples/SSR/parcel-react-ssr/server-stream for details
361386
1. Add your main bundle to the `head`, using __async__ script tag. Not defer! We have to do it async

0 commit comments

Comments
 (0)