Vue is built to handle most typical use cases efficiently without requiring a lot of manual tweaking. But sometimes, you’ll hit situations that need a bit more fine-tuning. In this article, we’ll go over the key things to keep an eye on for optimizing performance in a Vue app.
Page Load Performance vs. Update Performance
When talking about optimizing performance in Vue apps, there are two main aspects that should be explained:
- Page Load Performance - This is all about how quickly the app loads content and becomes usable the first time someone visits it. It’s usually measured with Core Web Vitals metric Largest Contentful Paint (LCP).
- Update Performance - This focuses on how quickly the app responds to user actions, for instance, how fast a list updates when someone types in a search box. It’s usually measured with Core Web Vitals metric Interaction to Next Paint (INP).
Ideally, we’d want to maximize both, but different frontend architectures make it easier or harder to hit performance goals in each area. Plus, the kind of app you’re building has a big impact on which performance aspects should be the priority.
This article will focus mainly on the things that you can do to improve performance of Vue apps, like built-in directives, plugins, and concepts. We won’t touch on other aspects of optimization, such as HTML,CSS, API improvements.
Performance Measuring Tools
To boost performance, we first need a way to measure it. Luckily, there are some excellent tools that allow you to audit/measure performance of Vue websites in local development, Continuous Integration, and also in production.
For checking load performance in production:
Testing performance during local development can be done with:
Finally, you can also measure performance in Continuous Integration with:
Improving Page Load
This is all about how quickly the app loads content and becomes usable the first time someone visits it.
Architecture
If fast page load times are crucial for your app, try to avoid making it a purely client-side SPA.
It’s better for the server to send HTML that already contains the content users need, as client-side rendering alone can slow down the time until content becomes visible. Server-Side Rendering (SSR) or Static Site Generation (SSG) can help with this. To learn more about how SSR can improve performance of your Vue application, check out this article.
If your app doesn’t need a lot of complex interactivity, you can also use a traditional backend server to render the HTML and add Vue for client-side enhancements.
If you need your main app to be an SPA but have marketing pages (like landing pages or blog pages), consider splitting them off! Ideally, these marketing pages should be deployed as static HTML with minimal JavaScript using static site generation.
Bundling
The less code we ship to the client/browser, the more performant our Vue application will be.
- Prefer dependencies that offer ES module formats and are tree-shaking friendly.
- Make sure to tree-shake any unused code. Many Vue plugins and integrations come with this setup by default.
- If you are using Vue primarily for progressive enhancement and prefer to avoid a build step, consider using petite-vue (only 6kb) instead.
- Check a dependency's size and evaluate whether it is worth the functionality it provides. Tools like bundlejs.com can be used for quick checks, but measuring with your actual build setup will always be the most accurate.