Code Monkey home page Code Monkey logo

Comments (4)

whilelucky avatar whilelucky commented on May 20, 2024

I see the problem but you haven't mentioned what it is that you're trying to achieve. Are you simply trying to add a new route? Or are you trying to add a new chunked route?

from pwa.

AnuragSinghTomarr avatar AnuragSinghTomarr commented on May 20, 2024

Thanks lakshya u looked into it. What i want to achieve is that suppose i am on pageA from which when i navigate i go to pageB then as soon as i navigate pageB bundle is downloaded, now from pageB i navigate to pageC so now pageC bundle is downloaded. There is no problem with this approach as in the route we can lazy import these bundles as per the route. What i want is PageA bundle contains PageB and PageC bundles also so that when i navigate from PageA to PageB then i already have PageB bundle. So bro let me know what i am doing wrong with mine webpack configuration.

from pwa.

whilelucky avatar whilelucky commented on May 20, 2024

The recommended approach to do this is to to wait for the LandingPage(PageA) route to render and then explicitly lazy import all the other routes FindPage and SearchPage(PageB and PageC) in the second .then of the LandingPage. For example:

<IndexRoute
  name="landing"
  getComponent={(_, cb) => {
    Promise.all([
      import('./views/LandingPage/LandingPage' /* webpackChunkName: 'landing' */),
      importCss('landing'),
    ]).then(([module]) => cb(null, module.default)).then(() => {
      import('./views/FindPage/FindPage' /* webpackChunkName: 'find' */);
      importCss('find');
      import('./views/CitiesPage/CitiesPage' /* webpackChunkName: 'cities' */);
      importCss('cities');
    });
  }}
/>

<Route
  name="find"
  path="/find/"
  getComponent={(_, cb) => {
    Promise.all([
      import('./views/FindPage/FindPage' /* webpackChunkName: 'find' */),
      importCss('find'),
    ]).then(([module]) => cb(null, module.default));
  }}
/>

<Route
  name="cities"
  path="/cities/"
  getComponent={(_, cb) => {
    Promise.all([
      import('./views/CitiesPage/CitiesPage' /* webpackChunkName: 'cities' */),
      importCss('cities'),
    ]).then(([module]) => cb(null, module.default));
  }}
/>

Advantage of this approach compared to bundling the 3 routes together is that you still keep separate chunks which means your time to first interactivity is still low. And, the other routes are lazy loaded on DOMContentLoaded so you're not competing for bandwidth with other critical resources.

from pwa.

AnuragSinghTomarr avatar AnuragSinghTomarr commented on May 20, 2024

Thanks bro... 👍

from pwa.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.