Twice script tags for the route requested in the SSR

I have an SSR repository (inferno-react like lib) linked using webpack. It has 2 route files, 1 for the server and 1 for the client, exactly the same, but on the client side, striping occurs using require.ensure. One of the routes looks like this:

<Route path="/home" getComponent={(props, cb) => {      
  require.ensure([], require => cb(null, 
  require('../views/containers/Home').default), 'home');
}}/>

Meaning, when the browser is parsed .htmland bundle.jsloaded in the browser, webpack will then insert this fragmented component of the .jsscript route into html and then it will load. But this slows it down a bit, since this route .jsloads only after loading bundle.js... So, I manually add a script tag from the server for any requested heap route dynamically using webpack-manifest-plugin, But now, for each requested route, I have a double script tag in file .htmlfor this fragmented component. One of them is that a server is manually added and one when we create chunk in webpack with require.ensure.

Everything works, but excellent 2 script tags!: /

Is there a way to avoid this, or how else can I handle this while keeping chunking on the client side.

+4
source share
1 answer

If you do not want to download the piece asynchronously, I would drop it require.ensureand just use requireit so that the code is included in your main package. Then you do not need any of the script tags except the main package inclusion.

Otherwise, if you want to fragment to separate code for different pages, use the second entry point instead of automatically generated fragments.

+1
source

Source: https://habr.com/ru/post/1683657/


All Articles