forked from stereobooster/react-snap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more documentation. Fixes stereobooster#78
- Loading branch information
1 parent
964ac66
commit 7d00f96
Showing
6 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Behind the scenes | ||
|
||
1. copies index.html as 200.html | ||
2. starts local web server with your application (by default uses `/build` as a root) | ||
3. visits `/` or any other pages listed in `include` configuration | ||
4. find all links on the page with the same domain, add them to queue | ||
5. If there is more than one page in the queue it also adds `/404.html` to the queue | ||
6. renders the page with the help of puppeteer | ||
7. waits till there are no active network requests for more than 0.5 second | ||
8. removes webpack chunks, if needed | ||
9. removes styles with blob URLs, if needed | ||
10. recreates text for style tags for CSS-in-JS solutions, if needed | ||
11. inlines critical CSS, if configured | ||
12. collects assets for http2 push manifest, if configured | ||
13. minifies HTML and saves it to the disk | ||
14. if `route` ends with `.html` it will be used as is, otherwise `route/index.html` is used | ||
|
||
## Other features | ||
|
||
- `react-snap` works concurrently, by default it uses 4 tabs in the browser. Can be configured with `concurrency` option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Load performance optimizations | ||
|
||
## Works out of the box | ||
|
||
### Prerendered HTML | ||
|
||
`react-snap` prerenders HTML, so the browser can start to render content or download required resources ASAP. | ||
|
||
### preconnect for third-party resources | ||
|
||
`react-snap` tracks all third-party connections during rendering and will place appropriate preconnect links in the `header`. | ||
|
||
### If you are using code splitting feature of Webpack | ||
|
||
`react-snap` will remove chunk scripts from the HTML and instead will place preload links in the `header`. | ||
|
||
### If you are using CSS-in-JS solution | ||
|
||
`react-snap` will prerender all styles and save in the HTML. | ||
|
||
## Requires configuration | ||
|
||
This is a brief overview of what described in Readme and [recipes](recipes.md). | ||
|
||
### inlineCss | ||
|
||
With this configuration enabled `react-snap` will inline critical CSS and stylesheet links will be loaded in a nonblocking manner with the help of [loadCss](https://www.npmjs.com/package/fg-loadcss). | ||
|
||
### cacheAjaxRequests | ||
|
||
If you are doing AJAX requests (to the same domain), `react-snap` can cache this data in the window. Think of it as a poor man's Redux rehydration. | ||
|
||
### http2PushManifest | ||
|
||
`react-snap` can record all resources (scripts, styles, images) required for the page and write down this data to the JSON file. You can use this JSON file to generate HTTP2 server pushes or Link headers. | ||
|
||
### If you are using Redux | ||
|
||
Use `window.snapSaveState` callback to store Redux state, so it can be used to rehydrate on the client side. | ||
|
||
### If you are using loadable-components | ||
|
||
Use `window.snapSaveState` callback to store `loadable-components` state, so it can be used to rehydrate on the client side. | ||
|
||
### If you are using Apollo | ||
|
||
Use `window.snapSaveState` callback to store `Apollo` state, so it can be used to rehydrate on the client side. | ||
|
||
**Caution**: I didn't test this one. If you use it please let me know. | ||
|
||
```js | ||
// Grab the state from a global variable injected into the server-generated HTML | ||
const preloadedState = window.__APOLLO_STORE__ | ||
|
||
// Allow the passed state to be garbage-collected | ||
delete window.__APOLLO_STORE__ | ||
|
||
const client = new ApolloClient({ | ||
initialState: preloadedState, | ||
}); | ||
|
||
// Tell react-snap how to save state | ||
window.snapSaveState = () => ({ | ||
"__APOLLO_STORE__": client.store.getState() | ||
}); | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters