Skip to content

Commit 098a99a

Browse files
committed
update readme
1 parent fe39c8b commit 098a99a

File tree

1 file changed

+47
-28
lines changed

1 file changed

+47
-28
lines changed

README.md

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<br/>
3232
</div>
3333

34-
👉 [Usage](#usage) | [API](#api) | [SSR](#ssr) | [Concurrent loading](#concurrent-loading) | [Webpack/Parcel](#bundler-integration)
34+
👉 [Usage](#usage) | [API](#api) | [Setup](#setup) | [SSR](#ssr) | [CCS](#css) [Concurrent loading](#concurrent-loading) | [Webpack/Parcel](#bundler-integration)
3535

3636

3737
Key features:
@@ -158,6 +158,8 @@ What you could load using `useImported`? Everything - `imported` itself is using
158158

159159
> `useImported` is an excellent example for loading translations, which are usually a simple json, in a _trackable_ way.
160160
161+
> 💡 did you know that there is another hook based solution to load _"something might might need"_? The [use-sidecar](https://github.com/theKashey/use-sidecar) pattern.
162+
161163
<a name="api"/>
162164

163165
# API
@@ -199,6 +201,8 @@ What you could load using `useImported`? Everything - `imported` itself is using
199201
- `rehydrateMarks([marks]):Promise`, loads _marked_ async chunks.
200202
- `injectLoadableTracker` - helper factory for the stream transformer
201203

204+
<a name="setup"/>
205+
202206
# Setup
203207

204208
## In short
@@ -238,6 +242,8 @@ If you need to search inside more that one top-level directory - just define mor
238242

239243
> The current implementation will discover and use all `imports`, even // commented ones
240244
245+
> 💡 Feel free to __.gitignore__ these autogenerated files
246+
241247
## 3. Start using `imported`, `lazy` or `useImported`
242248
Without you using API provided nothing would work.
243249

@@ -305,7 +311,7 @@ thus all scripts, used to render something on the Server would be loaded in a pa
305311
Literally - they are defined in the HTML.
306312
`React-imported-component` is different, it starts "working" when the bundle is loaded, thus
307313
__the loading of chunks is deferred__.
308-
> In the normals conditions `react-imported-component` would be "slower" than a "webpack" library.
314+
> 💡 In the normals conditions `react-imported-component` would be "slower" than a "webpack" library. Refer to bundle integration section.
309315
310316
However, it is not a problem, as long as (for now), script execution is single threaded, and even you if can __load__ multiple scripts
311317
simultaneously - you can't __run__ them in parallel*.
@@ -374,7 +380,7 @@ const reactRenderStream = ReactDOM.renderToNodeStream(...).pipe(importedTracker)
374380
This "hack", will first introduce all possible `imports` to the `imported-component`, then gave it a "tick"
375381
to start loading required once, and only then execute the rest of the bundle.
376382
While the rest(99%) of the bundle would make CPU busy - chunks would be loaded over the network.
377-
> This is utilizing the differences between `parse`(unenviable) phase of script, and execute one.
383+
> 💡This is utilizing the differences between `parse`(unenviable) phase of script, and execute(more expensive) one.
378384
379385
# Cooking receipts
380386

@@ -405,30 +411,7 @@ const AsyncComponent = imported(() => import('./myComponent.js'));
405411
<AsyncComponent/>
406412
</PrerenderedComponent>
407413
```
408-
React-prerendered-component is another way to work with code splitting, which makes everything far better.
409-
410-
411-
## CSS Support
412-
### CSS-in-JS Support
413-
First class. Literally CSS-in-JS library, like `styled-component` will do it by themselves, and there is nothing
414-
to be managed by this library
415-
416-
### Static CSS Support
417-
This library __does not__ support CSS as CSS, as long it's bundler independent. However, there is
418-
a bundler independent way to support CSS:
419-
1. Configure you bundler, and server side rendering to emit the right `classNames` (just remove `style-loader` from webpack configuration)
420-
2. Use `used-styles` to inject used __css files__ to the resulting HTML.
421-
422-
In short (streamed example is NOT short)
423-
```js
424-
const markup = ReactDOM.renderToString(<App />)
425-
const usedStyles = getUsedStyles(markup, lookup);
426-
```
427-
428-
If you need _stream render_ example with __reduced TTFB__, or critical style extraction -
429-
please refer to [used-styles](https://github.com/theKashey/used-styles) documentation, or our [parcel-bundler stream server example](https://github.com/theKashey/react-imported-component/tree/master/examples/SSR/parcel-react-ssr/stream-server).
430-
431-
> everything is possible
414+
`React-prerendered-component` is another way to work with code splitting, which makes everything far better.
432415

433416
## Timeout to display "spinners"
434417
There is no build in timeouts to display Error or Loading states. You could control everything by yourself
@@ -454,6 +437,40 @@ const MyPage = () => (
454437
);
455438
```
456439

440+
<a name="css"/>
441+
442+
## CSS Support
443+
### CSS-in-JS Support
444+
Out-of-the-box. Literally. CSS-in-JS library, like `styled-component` will do it by themselves, and there is nothing
445+
to be managed by this library.
446+
447+
### Static CSS Files Support
448+
> `imported` could knew only about JS you've used, not the CSS that js've used...
449+
450+
This library __does not__ support CSS as CSS, as long it's bundler independent and such deep integration is not possible.
451+
Even if [deep bundler integration](#bundler) is next following this section - the recomended solution is to skip `css` part of it, and use
452+
a more _bundler independent_ way to support CSS:
453+
454+
1. Configure you bundler, and server side rendering to emit the right `classNames` (just remove `style-loader` from webpack configuration)
455+
2. Use `used-styles` to inject used __css files__ to the resulting HTML.
456+
457+
In short (streamed example is NOT short)
458+
```js
459+
const lookup = discoverProjectStyles('./dist');
460+
// ....
461+
const markup = ReactDOM.renderToString(<App />)
462+
const usedStylesAsCSSFiles = getUsedStyles(markup, lookup);
463+
// generate `link` (better rel='preload') to load CSS files
464+
465+
const usedStylesAsStyles = getCriticalStyles(markup, lookup);
466+
// extract critical CSS and inline in to the server response
467+
```
468+
469+
If you need _stream render_ example with __reduced TTFB__ -
470+
please refer to [used-styles](https://github.com/theKashey/used-styles) documentation, or our [parcel-bundler stream server example](https://github.com/theKashey/react-imported-component/tree/master/examples/SSR/parcel-react-ssr/stream-server).
471+
472+
<a name="bundler-integration"/>
473+
457474
## Bundler integration
458475
Keep in mind - you dont "need" this. It will just make integration slightly better in terms of prefetching (which affects network recourse priority) and thus startup time.
459476

@@ -571,7 +588,9 @@ Another loaders exists, and the only difference is in API, and how they manage (
571588
* (webpack only) With [react-loadable](https://github.com/thejameskyle/react-loadable)
572589
* (not compatible with hooks) [react-async-component](https://github.com/ctrlplusb/react-async-component)
573590
* (webpack only) [loadable-components](https://github.com/smooth-code/loadable-components)
574-
* (webpack only) [react-universal-component](https://github.com/faceyspacey/react-universal-component)
591+
* (webpack only) [react-universal-component](https://github.com/faceyspacey/react-universal-component)
592+
593+
* (not a component loader) [use-sidecar](https://github.com/theKashey/use-sidecar)
575594

576595
## Licence
577596
MIT

0 commit comments

Comments
 (0)