Skip to content

Commit 402310d

Browse files
RiccardoMargiottacymen
authored andcommitted
Update usage example to better explain route-splitting and SSR.
1 parent f12b216 commit 402310d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,17 @@ ReactRailsUJS.useContext(myCustomContext)
172172

173173
If `require` fails to find your component, [`ReactRailsUJS`](#ujs) falls back to the global namespace, described in [Use with Asset Pipeline](#use-with-asset-pipeline).
174174

175-
In some cases, having multiple `require.context` may be desired - for example, if you have additional entry points to create JavaScript files for different routes, you would add multiple `require.context` to your `server_rendering.js` to allow for [Server-Side Rendering](#server-side-rendering) across your application. If so, an array of `require.context` can be passed to `ReactRailsUJS.useContexts`. With an array of contexts, an attempt will be made to `require` the component from each context before falling back to the global namespace as described above.
175+
In some cases, having multiple `require.context` entries may be desired. In a larger application, you might find it helpful to split your JavaScript by routes/controllers to avoid serving unused components and improve your site performance by keeping bundles smaller. For example, you might have separate bundles for homepage, search, and checkout routes. In that scenario, you can add an array of `require.context` component directory paths via `useContexts` to `server_rendering.js`, to allow for [Server-Side Rendering](#server-side-rendering) across your application
176176

177177
```js
178178
// server_rendering.js
179-
var applicationRequireContext = require.context('application', true);
179+
var homepageRequireContext = require.context('homepage', true);
180180
var searchRequireContext = require.context('search', true);
181181
var checkoutRequireContext = require.context('checkout', true);
182182

183183
var ReactRailsUJS = require('react_ujs');
184184
ReactRailsUJS.useContexts([
185-
applicationRequireContext,
185+
homepageRequireContext,
186186
searchRequireContext,
187187
checkoutRequireContext
188188
]);

0 commit comments

Comments
 (0)