Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load external assets only once accross isomorphic navigation? #373

Closed
rickysahu opened this issue Dec 10, 2016 · 6 comments
Closed

Comments

@rickysahu
Copy link

What's the best way to load an external JS file only once across different pages and components between navigation events? For example i need the google maps js file in one specific component used across many pages. Currently im using <script..> but each time the component loads, it reloads the external js file.
Obviously multiple loads adds additional bandwidth, but more importantly when the js file reloads, it breaks gmaps

@mikecardwell
Copy link

Can you provide some example code?

@mr47
Copy link
Contributor

mr47 commented Dec 17, 2016

@rickysahu it's require a dynamic modules, you can use require.ensure or wait #310.

Something like that:

export default class extends React.Component{
    componentDidMount(){
       require.ensure([], (require)=>{
          someModule = require("some-npm-module");
          someModule.init(this.someRefNode);
       })
    }
}

@babakness
Copy link

@mr47 Looks like #310 has merged, are you saying require.ensure is need with #310 merged or before?

@mr47
Copy link
Contributor

mr47 commented Dec 22, 2016

@babakness currently you need to setup a custom middleware to serve additional static file chunks that webpack generates (also need a tweak for webpack config), using #310 yes we can use require.ensure

PS: I am working to make some demo, so everybody can use this.

@impronunciable
Copy link
Contributor

Dynamic imports will be ready for next 2.1 #742

@sedubois
Copy link
Contributor

Does this also relate to #738?

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants