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

Lazy loading #35

Closed
dan-gamble opened this issue Dec 3, 2016 · 4 comments
Closed

Lazy loading #35

dan-gamble opened this issue Dec 3, 2016 · 4 comments

Comments

@dan-gamble
Copy link

dan-gamble commented Dec 3, 2016

Is it possible to only execute certain bits of code like we can with base webpack or vue-router require.ensure, System.import? If so would this be possible after generate too?

My use case is using highlight.js but i'd only wanna load this on certain routes

This question is available on Nuxt.js community (#c29)
@zspecza
Copy link

zspecza commented Dec 3, 2016

Hi @dan-gamble - I haven't used Nuxt.js much but @Atinux and I discussed this a lot a few weeks ago so based on that my assumption is it should be possible - and the in the code it looks like it is the default for the client build: https://github.com/nuxt/nuxt.js/blob/master/lib/app/router.js#L9

@Atinux Atinux added the question label Dec 4, 2016
@Atinux
Copy link
Member

Atinux commented Dec 4, 2016

@dan-gamble if you want to use highlight.js only on a specific page component, juste import it in your page component:

pages/about.vue:

<script>
import highlightjs from 'highlight.js'

export default {
}
</script>

Make sure that you don't use highlight.js in your config.build.vendor and config.plugins.

This way, highlight.js will be in the bundle of the /about page and we will be imported only when loading this route 👍

This is due to the code splitting we define in the router of Nuxt.js, like @declandewet described in his comment.

@Atinux Atinux closed this as completed Dec 4, 2016
@dan-gamble
Copy link
Author

Awesome, thanks guys.

@lock
Copy link

lock bot commented Nov 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 5, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants