Jobs by vuejobs.com
Overview #
Vue is designed to be performant for most common use cases without much need for manual optimizations. However, there are always challenging scenarios where extra fine-tuning is needed. In this section, we will discuss what you should pay attention to when it comes to performance in a Vue application.
First, let's discuss the two major aspects of web performance:
Page Load Performance: how fast the application shows content and becomes interactive on the initial visit. This is usually measured using web vital metrics like Largest Contentful Paint (LCP) and First Input Delay (FID).
Update Performance: how fast the application updates in response to user input. For example, how fast a list updates when the user types in a search box, or how fast the page switches when the user clicks a navigation link in a Single-Page Application (SPA).
While it would be ideal to maximize both, different frontend architectures tend to affect how easy it is to attain desired performance in these aspects. In addition, the type of application you are building greatly influences what you should prioritize in terms of performance. Therefore, the first step of ensuring optimal performance is picking the right architecture for the type of application you are building:
Consult Ways of Using Vue to see how you can leverage Vue in different ways.
(Video) Stromae - La solassitude (NMA Live Performance)Jason Miller discusses the types of web applications and their respective ideal implementation / delivery in Application Holotypes.
Profiling Options #
To improve performance, we need to first know how to measure it. There are a number of great tools that can help in this regard:
For profiling load performance of production deployments:
For profiling performance during local development:
- Chrome DevTools Performance Panel
- app.config.performance enables Vue-specific performance markers in Chrome DevTools' performance timeline.
- Vue DevTools Extension also provides a performance profiling feature.
Page Load Optimizations #
There are many framework-agnostic aspects for optimizing page load performance - check out this web.dev guide for a comprehensive round up. Here, we will primarily focus on techniques that are specific to Vue.
Choosing the Right Architecture #
If your use case is sensitive to page load performance, avoid shipping it as a pure client-side SPA. You want your server to be directly sending HTML containing the content the users want to see. Pure client-side rendering suffers from slow time-to-content. This can be mitigated with Server-Side Rendering (SSR) or Static Site Generation (SSG). Check out the SSR Guide to learn about performing SSR with Vue. If your app doesn't have rich interactivity requirements, you can also use a traditional backend server to render the HTML and enhance it with Vue on the client.
If your main application has to be an SPA, but has marketing pages (landing, about, blog), ship them separately! Your marketing pages should ideally be deployed as static HTML with minimal JS, by using SSG.
Bundle Size and Tree-shaking #
One of the most effective ways to improve page load performance is shipping smaller JavaScript bundles. Here are a few ways to reduce bundle size when using Vue:
Use a build step if possible.
Many of Vue's APIs are "tree-shakable" if bundled via a modern build tool. For example, if you don't use the built-in
<Transition>
component, it won't be included in the final production bundle. Tree-shaking can also remove other unused modules in your source code.(Video) GloRilla, Cardi B - Tomorrow 2 (Live From The 2022 American Music Awards)When using a build step, templates are pre-compiled so we don't need to ship the Vue compiler to the browser. This saves 14kb min+gzipped JavaScript and avoids the runtime compilation cost.
Be cautious of size when introducing new dependencies! In real world applications, bloated bundles are most often a result of introducing heavy dependencies without realizing it.
If using a build step, prefer dependencies that offer ES module formats and are tree-shaking friendly. For example, prefer
lodash-es
overlodash
.Check a dependency's size and evaluate whether it is worth the functionality it provides. Note if the dependency is tree-shaking friendly, the actual size increase will depend on the APIs you actually import from it. Tools like bundlejs.com can be used for quick checks, but measuring with your actual build setup will always be the most accurate.
If you are using Vue primarily for progressive enhancement and prefer to avoid a build step, consider using petite-vue (only 6kb) instead.
Code Splitting #
Code splitting is where a build tool splits the application bundle into multiple smaller chunks, which can then be loaded on demand or in parallel. With proper code splitting, features required at page load can be downloaded immediately, with additional chunks being lazy loaded only when needed, thus improving performance.
Bundlers like Rollup (which Vite is based upon) or webpack can automatically create split chunks by detecting the ESM dynamic import syntax:
js
// lazy.js and its dependencies will be split into a separate chunk// and only loaded when `loadLazy()` is called.function loadLazy() { return import('./lazy.js')}
Lazy loading is best used on features that are not immediately needed after initial page load. In Vue applications, this can be used in combination with Vue's Async Component feature to create split chunks for component trees:
js
import { defineAsyncComponent } from 'vue'// a separate chunk is created for Foo.vue and its dependencies.// it is only fetched on demand when the async component is// rendered on the page.const Foo = defineAsyncComponent(() => import('./Foo.vue'))
For applications using Vue Router, it is strongly recommended to use lazy loading for route components. Vue Router has explicit support for lazy loading, separate from defineAsyncComponent
. See Lazy Loading Routes for more details.
Update Optimizations #
Props Stability #
In Vue, a child component only updates when at least one of its received props has changed. Consider the following example:
template
<ListItem v-for="item in list" :id="item.id" :active-id="activeId" />
Inside the <ListItem>
component, it uses its id
and activeId
props to determine whether it is the currently active item. While this works, the problem is that whenever activeId
changes, every <ListItem>
in the list has to update!
Ideally, only the items whose active status changed should update. We can achieve that by moving the active status computation into the parent, and make <ListItem>
directly accept an active
prop instead:
template
<ListItem v-for="item in list" :id="item.id" :active="item.id === activeId" />
Now, for most components the active
prop will remain the same when activeId
changes, so they no longer need to update. In general, the idea is keeping the props passed to child components as stable as possible.
v-once
#
v-once
is a built-in directive that can be used to render content that relies on runtime data but never needs to update. The entire sub-tree it is used on will be skipped for all future updates. Consult its API reference for more details.
v-memo
#
v-memo
is a built-in directive that can be used to conditionally skip the update of large sub-trees or v-for
lists. Consult its API reference for more details.
General Optimizations #
The following tips affect both page load and update performance.
Virtualize Large Lists #
One of the most common performance issues in all frontend applications is rendering large lists. No matter how performant a framework is, rendering a list with thousands of items will be slow due to the sheer number of DOM nodes that the browser needs to handle.
However, we don't necessarily have to render all these nodes upfront. In most cases, the user's screen size can display only a small subset of our large list. We can greatly improve the performance with list virtualization, the technique of only rendering the items that are currently in or close to the viewport in a large list.
Implementing list virtualization isn't easy, luckily there are existing community libraries that you can directly use:
Reduce Reactivity Overhead for Large Immutable Structures #
Vue's reactivity system is deep by default. While this makes state management intuitive, it does create a certain level of overhead when the data size is large, because every property access triggers proxy traps that perform dependency tracking. This typically becomes noticeable when dealing with large arrays of deeply nested objects, where a single render needs to access 100,000+ properties, so it should only affect very specific use cases.
Vue does provide an escape hatch to opt-out of deep reactivity by using shallowRef() and shallowReactive(). Shallow APIs create state that is reactive only at the root level, and exposes all nested objects untouched. This keeps nested property access fast, with the trade-off being that we must now treat all nested objects as immutable, and updates can only be triggered by replacing the root state:
js
const shallowArray = shallowRef([ /* big list of deep objects */])// this won't trigger updates...shallowArray.value.push(newObject)// this does:shallowArray.value = [...shallowArray.value, newObject]// this won't trigger updates...shallowArray.value[0].foo = 1// this does:shallowArray.value = [ { ...shallowArray.value[0], foo: 1 }, ...shallowArray.value.slice(1)]
Avoid Unnecessary Component Abstractions #
Sometimes we may create renderless components or higher-order components (i.e. components that render other components with extra props) for better abstraction or code organization. While there is nothing wrong with this, do keep in mind that component instances are much more expensive than plain DOM nodes, and creating too many of them due to abstraction patterns will incur performance costs.
Note that reducing only a few instances won't have noticeable effect, so don't sweat it if the component is rendered only a few times in the app. The best scenario to consider this optimization is again in large lists. Imagine a list of 100 items where each item component contains many child components. Removing one unnecessary component abstraction here could result in a reduction of hundreds of component instances.
FAQs
How can I improve my VueJS performance? ›
- Asynchronous loading of components.
- Asynchronous loading routes.
- Image compression or using WebP images.
- Tree shaking of Unused CSS styles (when using a CSS frameworks)
When it comes to performance, Vue is an exceptionally fast tool. At an 22.9KB after gzipping, this technology will probably have a long life ahead of it.
How do I speed up Vue JS app? ›- 6 Ways to Speed Up Your Vue. js Application. ...
- Update Only What's Needed. One of the nastiest issues you can run into with VueJS is rendering the same elements or list of elements more times than needed. ...
- Eliminate Duplicate Rendering. ...
- Optimize Event Handling. ...
- Remove or Reduce Slow Components. ...
- Render Once. ...
- Virtual Scrolling.
Vue 2.0 is one of the fastest frameworks ever created. Its rendering layer was rewritten with the help of a lightweight Virtual DOM implementation forked from snabbdom. Since all dependencies are tracked during render, the system can determine which components need to reflect the changed state.
Is Vue or React faster? ›Vue is faster and smaller, which contributes to better performance. When it comes to hiring developers, both have their advantages and drawbacks. Vue is easier to learn, but React is more popular, and therefore, finding hires is faster.
Is Vue js better than React? ›Vue. js combined the top-level features of React and Angular, but its main feature is the perfect user experience. Also, it leveraged the capacity of the virtual DOM and optimized the code structure.
Is Vuejs good for big projects? ›Vue is easy to understand and absorb. The learning curve is less steep and development concepts are simple to understand. It helps to develop large-scale projects. The fact is that Vue adopted the best concepts of React and Angular.
Is Vuejs faster than Angular? ›Vue. js is a faster, simpler, and sleeker child of the React and Angular JS frameworks. Developed by Evan You in 2014, it has amassed a massive following in a very short time for its lightweight, progressive web development framework.
Why Vue is faster than React? ›Vue can be faster than React out of the box, due to more smart optimizations it is doing. React letting you do whatever you want, but not helping to do it. There is no difference how they handle states, or how they perform DOM manipulations.
How do I check my Vue performance? ›If you open the developer tools panel and navigate to the Vue performance tab, you will see the following report: You can use the metrics to pinpoint delays or bottlenecks that occur in your Vue component lifecycle.
What is lazy loading in VUE JS? ›
Lazy loading refers to an approach by which all the scripts are not loaded on the DOM as the application starts. Instead, they're only loaded when requested, which makes the JavaScript bundle size very small at initial load. Vue.
Is JS slow on mobile? ›JavaScript is the second-largest contributor to page weight, behind images, which means it can play a major role in slowing down the speed of your mobile site. Here's how you can reduce your reliance on JS and reduce its impact on your site.
Which IDE is best for Vuejs? ›- Best Code Editors (TLDR)
- VSCode Hottest.
- WebStorm/PhpStorm (JetBrains IDEs)
- CodeSandbox Rising Star.
- Atom.
- SublimeText.
- ESLint.
- Prettier.
- Limitations in making use of the community;
- Lack of scalability;
- Lack of plugins;
- Lack of highly experienced experts;
- Difficulties with mobile support;
- Difficulties with two-way binding;
- Excessive code flexibility.
React will still be the leading framework to learn in 2022. But consider that Vue is gaining momentum and popularity because it's easier to learn and get started. React's documentation is flawed, so you might think this framework would be very difficult to learn.
Why is Vuejs so popular? ›Vue. js is a popular JavaScript framework for front-end development developed and constantly updated by Evan You and his team. You can use this open-source framework to develop any single-page application or user interface. The design is very flexible and focuses on declarative rendering and component composition.
Is Vue catching up to React? ›There are also around 68,000 npm packages. React now has 165,000 stars on Github, which is roughly 15,000 fewer than Vue's 180,000. According to Google Trends data, React has outperformed Vue in terms of search relevancy over the last 12 months.
Which big companies use Vuejs? ›...
In 2022, you will find that several of the global websites using Vue. js have global notoriety.
- Facebook.
- Netflix.
- Xiaomi.
- Adobe.
- The Motley Fool.
- Trivago.
- Grammarly.
- Gitlab.
Vue. JS is the trendiest front-end framework according to GitHub currently being preferred more by people than other front-end Javascript frameworks like React and Angular. Vue. JS's future looks much promising as a Javascript front-end framework.
Does Facebook use Vue or React? ›Facebook's Newsfeed
Many teams working on new projects these days pick Vue, because it's a pleasure to work with. It's easy to start a project in Vue, and since the framework is not difficult to learn, developers less familiar with it can catch up quickly.
Is Vue more difficult than React? ›
React documentation is slightly harder to read, which resulted in a slow ramp-up in comparison with Vue. js, mostly based on the extra effort to learn JSX. In summary, both are quite similar in their structure, but Vue. js is slightly easier to learn as it allows HTML and JSX.
Is Vue better than bootstrap? ›According to the StackShare community, Bootstrap has a broader approval, being mentioned in 7044 company stacks & 1115 developers stacks; compared to Vue. js, which is listed in 849 company stacks and 1219 developer stacks.
Is Vue better than Angular? ›Vue is simpler to use than Angular since it has built-in app templates and allows for more flexibility. Furthermore, it is easy to integrate Angular or React-based mobility solutions into the Vue platform as Vue. js was created by combining Angular and React.
Which is better node JS or VueJS? ›Node. js is a cross-platform and open-source back-end framework that executes JavaScript code on the server-side. Vue. js is a structural, open-source JavaScript framework that is used for building UIs and single-page applications.
Is VueJS scalable? ›Vue. js is flexible and scalable. In practice, this means that it can be used for a huge, modular SPA (Single Page Apps) as well as to construct small, interactive parts to be integrated using a different technology.
Is VueJS good for SEO? ›Vue. js has solutions that work well for SEO, but you don't get them by default. Your developers should know how to use Vue SEO modules (vue-meta, vue-router, Webpack, Nuxt. js framework) and build the app architecture and infrastructure accordingly.
Is Vue cleaner than React? ›Vue also uses the virtual DOM, but compared to React, Vue has better performance and stability. According to this data, Vue and React's performance difference is subtle since it is only a few milliseconds. This proves that Vue and React are very similar in terms of performance.
Is Vuejs still relevant? ›js is an easy-to-learn and flexible JavaScript framework used for building interfaces and single-page applications. With 197k stars on Github, Vue. js has attained much popularity among developers in a relatively short span of time and is even predicted to eventually edge out React as the most popular JS technology.
Is Vue still popular? ›Popularity. According to a survey by Stack Overflow 40.13% of the developers believe that React is the most commonly used JavaScript Framework. Angular and Vue follow it with 22.96% and 18.97%, respectively.
How lightweight is Vue? ›Vue is lightweight, easy to learn, pleasant to write in, and not difficult to integrate with legacy technologies or an application without a specified framework. Because of its familiar templating syntax and use of components, integrating or migrating existing projects to Vue is faster and smoother.
Is working at Vue hard? ›
Working at Vue
Easy job to get and not too hard to do, staff are nice and friendly, benefits are quite good too. Typical day is either working on concessions behind the tills making food/serving customers or on the floor cleaning and checking screens.
However, Odeon, says its adverts and trailers length are typically 15 to 25 minutes but notes that this varies with each performance. Vue also says that customers should allow 20 minutes from the start time for ads and trailers.
Is lazy loading good for performance? ›The benefits of lazy loading include: Reduces initial load time – Lazy loading a webpage reduces page weight, allowing for a quicker page load time. Bandwidth conservation – Lazy loading conserves bandwidth by delivering content to users only if it's requested.
Does lazy loading improve performance? ›Lazy-loading images and video reduces initial page load time, initial page weight, and system resource usage, all of which have positive impacts on performance.
Is lazy loading better? ›Today, lazy loading is widely used in web applications to improve application performance. It helps developers reduce loading times, optimize data usage and improve the user experience. However, overusing lazy loading can affect the application performance negatively.
Which JS framework is fastest? ›Vue. js is the fastest JS framework available.
Which JavaScript engine is fastest? ›V8. While Nashorn and GraalVM JavaScript are engines completely written in Java, V8 is a native implementation by Google. V8 is known to be fast with a very short ramp-up time. It is the fastest of the three alternatives and runs with Java 8, 11, and higher.
Is JS as fast as C? ›JavaScript appears to be almost 4 times faster than C++! I let both of the languages to do the same job on my i5-430M laptop, performing a = a + b for 100000000 times. C++ takes about 410 ms, while JavaScript takes only about 120 ms.
Does Spotify use Vue? ›vue-spotify
Spotify client built with vue. js / vuex. Authenticated users must have a valid Spotify Premium subscription because if it doesn't, Web Playback SDK will not work.
js vs jQuery, it is clear that the Vue is much easier and better compared to jQuery in any respect. The discussion above shades some important light on the use cases and implementation of the same examples using Vue.
Does Alibaba use Vue? ›
Alibaba Cloud offers the following two types of exams. The same Pearson VUE web account is used to schedule either type of exam.
Are Vue developers in demand? ›There is high demand from companies and other organisations around the world for Vue. js developers, either hired directly as employees or via third-party IT outsourcing and software and web development agencies.
Is Vue full stack? ›js, Vue, and Node. js) is a popular NEW stack for building full-stack web applications. It allows developers to write an entire application—front-end, back-end, and database—using only JavaScript.
Is Vue good for web development? ›Vue. js is one of the most popularly used JS frameworks for developing UIs and single-page applications. Developers prefer this progressive framework as it offers easy-to-use syntax and clean formatting styles. Besides, it also gets easily integrated into other infrastructure as well.
How can I improve my script performance? ›- Use a UI Policy instead.
- Reduce server lookups.
- Avoid global client scripts.
- Add the isLoading check to onChange scripts.
- Add the newValue check.
- Run server calls as late as possible within the script.
Simply put, Vue CLI's hot reload is a feature that automatically restarts the server and reflects changes in the browser when you enter the save key ([Ctrl +s] on Windows, [Cmd + s] on Mac) when you edit code.
How long should a 2 hour script be? ›Scripts written in proper screenplay format average a page per minute. A feature is roughly an hour-and-a-half – two hours long. Thus the 90 – 120 page rule. Screenwriting books and expensive screenwriting gurus will all tell you that scripts should fall within the 90-120 page rule.
How long should a 1 hour script be? ›Generally speaking, hour-long episode scripts can be anywhere from 45-63 pages, although a majority of the time you want to stick with 50-55 pages. The basic sense of it is that one page equals one minute, and with a 60-minute show, you obviously need to account for commercial breaks.
How long is script for 1 hour? ›This rule of thumb also applies broadly to feature film scripts. So, if you want to write an hour-long pilot for a traditional network, aim for around 44 or 45 pages. If you plan to write an hour-long pilot for a premium channel or streaming service, aim for a script in the neighborhood of 55-65 pages.
How does Vuejs work under the hood? ›Under the hood Vue will walk through all the properties that we define into the data and converts them to getter/setters using Object. defineProperty. When any data property gets a new value then the set function will notify the Watchers. A Watcher is created for each component when a Vue application is initialized.
Does Vue automatically update? ›
One of Vue's best features is reactivity. You change a variable, and Vue automatically updates what is rendered to the page. However, not everything in Vue is reactive by default. If we want a variable to be reactive, we need to make sure that Vue knows about it.
What is the difference between hot restart and hot reload? ›A hot restart has a slightly different functionality as compared to a hot reload. It is faster as compared to the full restart function. It destroys the preserved states of our app, and the code gets fully compiled again and starts from the default state.