SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
How to
Optimize the
Performance
of Vue js
Large
Application
Structure?
www.bacancytechnology.com
Suppose you have worked hard on
developing an entire Vue.js application. But
didn’t prioritize its performance; now, your
application takes a while to load, navigate,
submit, or take any user actions. Do you
think users would like such delayed
experiences or prefer to stay a little longer
on your Vue js application?
Sadly, the answer is No. According to
statics, it has been proved that 53% user
doesn’t choose to spend time on those
applications which takes more than 3
seconds to load. Building an application
with optimized performance will smoothen
the user experience and gradually increase
user interactions.
Unfortunately, most developers fail to
understand the importance of performance
and end up building an extensive
application with performance issues. I
assume you don’t want to be one of those
developers. It’s challenging to develop an
application, but it is more challenging to
develop an optimized performance
application. To lessen your challenges, I
have come up with this blog post that will
help you understand how you can optimize
the structure of your Vue.js app
Lazy Loading in Vue js
Code splitting based on Routes
Vue js Prefetch components
Table of Index
1. Introduction of Vue js App Structure
2. Vue js Performance Optimization: The
Hour of Need
3. Performance Pitfalls in Vue js
4. How to Check Your Vue js application’s
Bundle Size?
5. Optimizing the Performance of Vue js
Large Application Structure
6. Vue.js Performance: Optimize Third-
party Library
7. Conclusion
Introduction
of Vue js App
Structure
VueJS is the most popular and stable
JavaScript framework for developing
websites, but just like other frameworks,
the performance will be compromised if
you overlook it. If you are looking for sure
shot Vue js performance optimization tips
or just want to know vue best practices, for
your large scale application you have
chosen the correct blog. Without much ado,
let’s discuss in detail how you can optimize
the performance of Vue js large application
structure.
It’s essential first to understand the Vue js
app architecture. By knowing its
importance, we can be aware of how crucial
it is, and we would start taking it more
seriously. So, let’s look at why there’s a need
to optimize your large scale application.
Please keep in mind that optimization of
any application is essential, but as this blog
concerns, we’ll be discussing it.
Vue JS
Performance
Optimization:
The Hour of
Need
No programmer will ever want that even
after coding thousands of lines, users don’t
want to spend time on the application
because of the time it takes to perform user
actions.
Product owners around the world develop
products for users, and these users are
mainly concerned with their smooth
interactions. It does not concern the end-
users how much effort programmers have
invested in Vue JS app architecture if they
are not satisfied with Vue js speed and
efficiency.
So, yes, that is why it becomes mandatory
criteria to optimize the performance that
will eventually satisfy the end-users’ needs.
Performance
Pitfalls in
Vue JS
Let’s look at how Vue js works and the
significant reasons behind poor Vue
performance.
The reasons for slowing down the Vue
performance depend upon your Vue js app
structure. For example, one of the
significant reasons behind poor
performance in Vue jS Single Page
Applications (SPAs) may vary from the
VueJS projects dealing with Server Side
Rendering (SSR).
The primary and foremost reason any
developer can think of whether the
application is SPA or having SSR is bundle
size. The larger the bundle size slower the
Vue js performance. Thus we can conclude
that bundle size is inversely proportional to
the application performance.
Not using third-party libraries wisely
Overlooking Code Splitting and Lazy
Loading
Unwanted hits to API requests
Not structuring JS and CSS files
properly
Some of the common reasons behind Vue js
large application-
Before discussing how to reduce the bundle
size, let’s see how to check the size of the
Vue js and Vue js enterprise application’s
bundle size.
How to Check
the Bundle
Size of your
VueJS app?
I’ll be showing you two ways to check the
bundle size of the Vue js application.
1. To generate a report
Generating reports give you a visual
description of the sizes of various packages
used. Further, you can figure out to replace
any package which takes more space than
expected. You can use the command build –
report for generating the report of your
application. Keep in mind that this
command will build a report of the
application which has installed webpack-
bundle-analyzer.
After running the command as mentioned
above, open the package.json file and add
this –
"build-report": "vue-cli-service build --
report"
And then execute this –
npm run build-report
After performing all this, a file named –
report.html will be created in the dist
folder.On opening that file, you’ll observe
this –
2. Run command – npm run build
You will see something like this image.
Now, after finding the bundle size, the
struggle is to reduce that. Without further
ado, let’s proceed and explore the ways of
Vue.js app performance optimization.
Optimizing
the
Performance
of Vue js
Large
Application
Structure
Here are some VueJS performance tips that
you can implement to optimize the
performance of Vue.js application.
As per the name, Lazy Loading in Vue js is
the method of loading the modules in your
application lazily, i.e., when the user
actually needs that module. Most of the
time, there’s no need to load all the modules
from the JavaScript bundle whenever users
visit the website.
There are some components having modals
and tooltips that can be loaded when
needed. You won’t see the result if you’re
dealing with two or three modals or tooltips
but, assume that you have an extensive Vue
application with so many modals and
tooltips; loading them at a time can lessen
your performance.
1. Lazy Loading in Vue js
It is not at all worthy of loading the entire
bundle every time the page loads. Thus, it
loading helps you to divide the bundle and
load them when it is used. This way, it saves
time by not downloading and parsing the
unnecessary code.
To check the actual
JavaScript code being used
in the website –
1. Click devtools
2. cmd + shift + p
3. Type coverage
4. Click record
The URLs with red highlights are not in use
and can be loaded lazily. By taking
advantage of lazy loading, you can reduce
the bundle size by 60%.
This was about what and why we should
load components and modules lazily in
large scale application; let’s explore How to
enforce it.
We can use Webpack Dynamic Imports
rather than regular imports to separate the
chunk of modules that have to be loaded
lazily.
// demo.js
const Demo = {
testDemo: function () {
console.log("This is just a demo!")
}
}
export default Demo
// app.js
import Demo from './demo.js'
Demo.testDemo()
This is how you import
your JavaScript files, right?
It will add the file demo.js as the node to
app.js in its dependency graph and bundle it
together by importing it in such a manner.
So, whenever the bundle is loaded, demo.js
will be loaded irrespective of its need.
But, what if we want to load demo.js only as
of the response of some user actions. In
such a case, we will implement dynamic
importing, telling the application to
download this module only when needed.
Here is the modification
was done to the above
code for executing
dynamic imports for
testing Vue.js app
// app.js
const getDemo = () => import('./demo.js')
// later when some user action tasks place
as hitting the route
getDemo()
.then({ testDemo } => testDemo())
So, you can notice that instead of importing
the Demo module directly, I have declared a
function which indeed returns the import()
function. And this is what we call dynamic
importing, due to which the webpack will
know that it has to keep this module in a
separate file. The function getDemo(), which
contains the dynamic import, returns the
Promise. We are basically cutting off the
node ( here Demo ) from the dependency
graph and later downloading it when
needed ( such as route changing or clicking
). Keep in mind that the modules imported
in Demo.js will also be isolated from the
bundle.
Lazy Loading in Vue js is one of the best
practices to reduce bundle size and
optimize performance. Develop a habit of
knowing which modules you don’t need
unless there’s an explicit user action and
download them lazily for better
performance.
Assume you have to develop a small VueJS
website with two web pages – Dashboard
and Contact. Even for these two pages, you
need to implement vue-router in your
project.
// routing.js
import Dashboard from './Dashboard.vue'
import Contact from './Contact.vue'
const routes = [
{ path: '/', component: Dashboard }
{ path: '/contact, component: Contact }
]
2. Code splitting based
on Routes
Your routing file may look like
this-
Due to this standard coding method, the
components – Dashboard and Contact (
with lodash)- will be downloaded even
when the user visits another page, where
we neither want to download Dashboard
nor Contact. It is because we have both the
routes in the same bundle. You might think
what is a big deal with downloading two
extra pages. But, this matters when you’re
dealing with large applications with huge
bundles.
To avoid this unnecessary downloading of
the components, we will use split the
code.And for that, we will be having
separate bundles for different routes which
we follow the technique of dynamic
imports.
Rather than importing the components
directly, you will now pass the dynamic
routes. Let’s see how to achieve this.
// routing.js
const routes = [
{ path: '/', component: () =>
import('./Dashboard.vue') }
{ path: '/contact, component: () =>
import('./Contact.vue') }
]
By following this practice, you can decrease
your bundle size to its half! But for that, you
need to be sure which components can be
used with dynamic imports. Believe me,
such vue js practice will help your
application to be more performant.
Let’s move ahead and dive deeper into Vue
js prefetch components is a technique to
download the resources before the user
requests the page. For example, if you are
sure that most users will visit the product
page from the category page, you can think
of prefetching the product page. You need
to keep in mind that only after the initial
render prefetching can take place. Another
benefit of prefetching is that it removes the
unwanted consequences caused due to lazy
loading without affecting performance.
3. Vue js Prefetch
components
For its implementation you just need to add
< link rel="prefetch" href="url" /> tag.
Simple, right? But the case is different when
dealing with webpack, which generates the
bundle names based on the module’s order.
Luckily, webpack has magic comments to
prefetch easily. Magic comments are
comments affecting the build’s process. We
need to use – /* webpackPrefetch: true */
for prefetching the modules. Just keep it in
your dynamic imports as displayed below –
components: {
ModalView: () => import(/*
webpackPrefetch: true */ './ModalView.vue')
}
While executing the code, webpack will
search for magic comments and add < link
rel="prefetch" url="resource-url" /> in the
head section.
< link rel="prefetch" href="path-to-chunk-
with-modal-view" />
Whenever the user requests the ModalView
module, it will be prefetched already and
accessible instantly.
Vue.js
Performance:
Optimize Third-
party Library
When you check how much is your bundle
size and are surprised if it crosses the ideal
number, it’s not always because of what you
code; so many times, the reason is the usage
of loaded third-party libraries. Yes, we all
use third-party libraries without knowing
their impact on our application’s
performance. Our code might be a tiny part
of the bundle size.
You can use bundlephobia to know how do
different libraries can affect performance.
You just need to add the Vuejs library name
to this fantastic website, and you’ll gain a
lot of knowledge related to your website-
data. For example, I’ve used lodash library,
and here is the information.
Isn’t this awesome to know more about the
libraries and their effects on the
performance.
If you want to know which Vue js libraries
have more impact on your VueJS
application, then you can click here to scan
your package.json. Apart from this, I have
already made clear the various methods for
analyzing the bundle size.
Why do I want to use the library?
Do I need the whole library for my
purpose?
What is the impact of the library I
chose?
Do I have a performance-friendly way
of using the library?
Let’s take a look at how I deal when I’m
choosing a Vue library.
If I need some functions for my program for
which I’ll like to install lodash library.But,
as I’m aware of how much lodash would
cost to the performance so rather than
importing the whole library, I’ll just import
the functions, like this-
Before choosing any
library, ask these
questions to yourself;
import isEmpty from 'lodash/isEmpty`
Trust me, making such small changes in
different libraries will create a more
significant and noticeable impact.
So far, we have dealt with the bundle size of
VueJS large scale application and VueJS
performance tips for the same. For
optimizing performance, reducing bundle
size is not the only solution. It’s essential to
reuse some of the assets so that users don’t
have to wait. In our next step, let’s see how
to use the browser cache for reusing.
Using Browser Cache
We have discussed enough regarding
bundle size; in this last step, we will focus
on caching the data.
Caching is a technique of storing selective
data to access it quickly when requested.
The browser preserves the data in the
memory cache until the browser is not
closed.
You can observe this by yourself.
Open your developer tool and select the
Network tab. Visit any website and reload it
few times. You’ll notice that some of the
static files like CSS, images, javascript, and
HTML will have a memory cache, as shown
below. This means that such files are being
served from the memory cache.
As browsers are handling caches pretty well
by themselves. You might think, what can
we add to this? So, you just need to figure
out which parts of your VueJS app structure
change rarely compared to others so that
we can cache those parts.
Assume the structure of
your project to be like
this-
main.[hash].js – root component of your
project
common.[hash].js – common
components of your project
dashboard.[hash].js – dashboard specific
components
contact.[hash].js – contact specific
components
The part that concerns us is common.
[hash].js. We can have all the dependencies
here, which are not likely to change often,
and we can further use it for caching the
data. By separating such components, you
are saving your users’ time. You can visit
here to read more about how to separate
the dependencies into different parts.
So, this was all about how to optimize your
VueJS app performance. I hope that all your
questions and queries are answered
through this blog.
No matter how large scale application you
have developed, it requires to be optimized
at some point. If you are looking to hire
VueJS developer for optimizing your Vue.js
app to satisfying your end-users, then you
are just one click away. Get in touch with
Bacancy Technology to experience one-of-
a-kind Vue js best practices and Vue.js
application development services. We are
globally acknowledged for offering
advanced vue.js application architecture.
Conclusion
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Design patterns 1july
Design patterns 1julyDesign patterns 1july
Design patterns 1july
Edureka!
 
Developing solid applications
Developing solid applicationsDeveloping solid applications
Developing solid applications
Nilesh Bangar
 
Frontend Development Bootcamp - React [Online & Offline] In Bangla
Frontend Development Bootcamp - React [Online & Offline] In BanglaFrontend Development Bootcamp - React [Online & Offline] In Bangla
Frontend Development Bootcamp - React [Online & Offline] In Bangla
Stack Learner
 
Joomla guide-final
Joomla guide-finalJoomla guide-final
Joomla guide-final
chirag4040
 

Was ist angesagt? (20)

Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Implementing Web Services In Java
Implementing Web Services In JavaImplementing Web Services In Java
Implementing Web Services In Java
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
Getting Started With AngularJS
Getting Started With AngularJSGetting Started With AngularJS
Getting Started With AngularJS
 
10 things to remember
10 things to remember10 things to remember
10 things to remember
 
Learn How to Animate your Android App
Learn How to Animate your Android AppLearn How to Animate your Android App
Learn How to Animate your Android App
 
Top 12 Vue.js Developer Tools and Component Libraries (To Speed Up Vue.js Dev...
Top 12 Vue.js Developer Tools and Component Libraries (To Speed Up Vue.js Dev...Top 12 Vue.js Developer Tools and Component Libraries (To Speed Up Vue.js Dev...
Top 12 Vue.js Developer Tools and Component Libraries (To Speed Up Vue.js Dev...
 
Browser Based Performance Testing and Tuning
Browser Based Performance Testing and TuningBrowser Based Performance Testing and Tuning
Browser Based Performance Testing and Tuning
 
A report on mvc using the information
A report on mvc using the informationA report on mvc using the information
A report on mvc using the information
 
Develop Mobile App Using Android Lollipop
Develop Mobile App Using Android LollipopDevelop Mobile App Using Android Lollipop
Develop Mobile App Using Android Lollipop
 
The Superhero’s Method of Modern HTML5 Development by RapidValue Solutions
The Superhero’s Method of Modern HTML5 Development by RapidValue SolutionsThe Superhero’s Method of Modern HTML5 Development by RapidValue Solutions
The Superhero’s Method of Modern HTML5 Development by RapidValue Solutions
 
Design patterns 1july
Design patterns 1julyDesign patterns 1july
Design patterns 1july
 
Single page applications
Single page applicationsSingle page applications
Single page applications
 
Developing solid applications
Developing solid applicationsDeveloping solid applications
Developing solid applications
 
Project report - Web Browser in Java by Devansh Koolwal
Project report - Web Browser in Java by Devansh KoolwalProject report - Web Browser in Java by Devansh Koolwal
Project report - Web Browser in Java by Devansh Koolwal
 
Create Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
 
Frontend Development Bootcamp - React [Online & Offline] In Bangla
Frontend Development Bootcamp - React [Online & Offline] In BanglaFrontend Development Bootcamp - React [Online & Offline] In Bangla
Frontend Development Bootcamp - React [Online & Offline] In Bangla
 
Joomla guide-final
Joomla guide-finalJoomla guide-final
Joomla guide-final
 

Ähnlich wie How to optimize the performance of vue js large application structure

COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docx
write31
 

Ähnlich wie How to optimize the performance of vue js large application structure (20)

Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023Vue Js vs React: Which is the Best JS Technology in 2023
Vue Js vs React: Which is the Best JS Technology in 2023
 
Vue js & vue cli 3 plugins to boost up the performance of your application
Vue js & vue cli 3 plugins to boost up the performance of your applicationVue js & vue cli 3 plugins to boost up the performance of your application
Vue js & vue cli 3 plugins to boost up the performance of your application
 
Vue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptxVue Or React - Which One is the Best_.pptx
Vue Or React - Which One is the Best_.pptx
 
React vs. vue which framework to select and when
React vs. vue  which framework to select and when React vs. vue  which framework to select and when
React vs. vue which framework to select and when
 
What is Vuejs.pptx
What is Vuejs.pptxWhat is Vuejs.pptx
What is Vuejs.pptx
 
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web ApplicationReact Js vs Node Js_ Which Framework to Choose for Your Next Web Application
React Js vs Node Js_ Which Framework to Choose for Your Next Web Application
 
COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docx
 
Review on React JS
Review on React JSReview on React JS
Review on React JS
 
React vs. vue which framework to select and when
React vs. vue  which framework to select and when React vs. vue  which framework to select and when
React vs. vue which framework to select and when
 
React Vs Vue.js Which One is Better.pdf
React Vs Vue.js Which One is Better.pdfReact Vs Vue.js Which One is Better.pdf
React Vs Vue.js Which One is Better.pdf
 
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdfSure Shot Ways To Improve And Scale Your Node js Performance.pdf
Sure Shot Ways To Improve And Scale Your Node js Performance.pdf
 
Word press with react – implementing headless wordpress with reactjs converted
Word press with react – implementing headless wordpress with reactjs convertedWord press with react – implementing headless wordpress with reactjs converted
Word press with react – implementing headless wordpress with reactjs converted
 
An introduction to AngularJS
An introduction to AngularJSAn introduction to AngularJS
An introduction to AngularJS
 
Asp.net Vs Vue.js.pdf
Asp.net Vs Vue.js.pdfAsp.net Vs Vue.js.pdf
Asp.net Vs Vue.js.pdf
 
Is Vue catching up with React.pdf
Is Vue catching up with React.pdfIs Vue catching up with React.pdf
Is Vue catching up with React.pdf
 
9 Best JavaScript Frameworks To Choose
9 Best JavaScript Frameworks To Choose9 Best JavaScript Frameworks To Choose
9 Best JavaScript Frameworks To Choose
 
Asp Net Vs Vue JS Which One You Should Choose for Development.pdf
Asp Net Vs Vue JS Which One You Should Choose for Development.pdfAsp Net Vs Vue JS Which One You Should Choose for Development.pdf
Asp Net Vs Vue JS Which One You Should Choose for Development.pdf
 
Why do JavaScript enthusiast think of Vue.js for building real-time web appli...
Why do JavaScript enthusiast think of Vue.js for building real-time web appli...Why do JavaScript enthusiast think of Vue.js for building real-time web appli...
Why do JavaScript enthusiast think of Vue.js for building real-time web appli...
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 
How backbone.js is different from ember.js?
How backbone.js is different from ember.js?How backbone.js is different from ember.js?
How backbone.js is different from ember.js?
 

Mehr von Katy Slemon

Mehr von Katy Slemon (20)

React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdfReact Alternatives Frameworks- Lightweight Javascript Libraries.pdf
React Alternatives Frameworks- Lightweight Javascript Libraries.pdf
 
Data Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdfData Science Use Cases in Retail & Healthcare Industries.pdf
Data Science Use Cases in Retail & Healthcare Industries.pdf
 
How Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdfHow Much Does It Cost To Hire Golang Developer.pdf
How Much Does It Cost To Hire Golang Developer.pdf
 
What’s New in Flutter 3.pdf
What’s New in Flutter 3.pdfWhat’s New in Flutter 3.pdf
What’s New in Flutter 3.pdf
 
Why Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdfWhy Use Ruby On Rails.pdf
Why Use Ruby On Rails.pdf
 
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdfHow Much Does It Cost To Hire Full Stack Developer In 2022.pdf
How Much Does It Cost To Hire Full Stack Developer In 2022.pdf
 
How to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdfHow to Implement Middleware Pipeline in VueJS.pdf
How to Implement Middleware Pipeline in VueJS.pdf
 
How to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdfHow to Build Laravel Package Using Composer.pdf
How to Build Laravel Package Using Composer.pdf
 
How to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdfHow to Develop Slack Bot Using Golang.pdf
How to Develop Slack Bot Using Golang.pdf
 
IoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdfIoT Based Battery Management System in Electric Vehicles.pdf
IoT Based Battery Management System in Electric Vehicles.pdf
 
Understanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdfUnderstanding Flexbox Layout in React Native.pdf
Understanding Flexbox Layout in React Native.pdf
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
New Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdfNew Features in iOS 15 and Swift 5.5.pdf
New Features in iOS 15 and Swift 5.5.pdf
 
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdfHow to Hire & Manage Dedicated Team For Your Next Product Development.pdf
How to Hire & Manage Dedicated Team For Your Next Product Development.pdf
 
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdfChoose the Right Battery Management System for Lithium Ion Batteries.pdf
Choose the Right Battery Management System for Lithium Ion Batteries.pdf
 
Flutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdfFlutter Performance Tuning Best Practices From the Pros.pdf
Flutter Performance Tuning Best Practices From the Pros.pdf
 
Angular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdfAngular Universal How to Build Angular SEO Friendly App.pdf
Angular Universal How to Build Angular SEO Friendly App.pdf
 
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdfHow to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
How to Set Up and Send Mails Using SendGrid in NodeJs App.pdf
 
Ruby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdfRuby On Rails Performance Tuning Guide.pdf
Ruby On Rails Performance Tuning Guide.pdf
 
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdfUncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
Uncovering 04 Main Types and Benefits of Salesforce ISV Partnerships.pdf
 

Kürzlich hochgeladen

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Kürzlich hochgeladen (20)

PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 

How to optimize the performance of vue js large application structure

  • 1. How to Optimize the Performance of Vue js Large Application Structure? www.bacancytechnology.com
  • 2. Suppose you have worked hard on developing an entire Vue.js application. But didn’t prioritize its performance; now, your application takes a while to load, navigate, submit, or take any user actions. Do you think users would like such delayed experiences or prefer to stay a little longer on your Vue js application? Sadly, the answer is No. According to statics, it has been proved that 53% user doesn’t choose to spend time on those applications which takes more than 3 seconds to load. Building an application with optimized performance will smoothen the user experience and gradually increase user interactions.
  • 3. Unfortunately, most developers fail to understand the importance of performance and end up building an extensive application with performance issues. I assume you don’t want to be one of those developers. It’s challenging to develop an application, but it is more challenging to develop an optimized performance application. To lessen your challenges, I have come up with this blog post that will help you understand how you can optimize the structure of your Vue.js app
  • 4. Lazy Loading in Vue js Code splitting based on Routes Vue js Prefetch components Table of Index 1. Introduction of Vue js App Structure 2. Vue js Performance Optimization: The Hour of Need 3. Performance Pitfalls in Vue js 4. How to Check Your Vue js application’s Bundle Size? 5. Optimizing the Performance of Vue js Large Application Structure 6. Vue.js Performance: Optimize Third- party Library 7. Conclusion
  • 5. Introduction of Vue js App Structure
  • 6. VueJS is the most popular and stable JavaScript framework for developing websites, but just like other frameworks, the performance will be compromised if you overlook it. If you are looking for sure shot Vue js performance optimization tips or just want to know vue best practices, for your large scale application you have chosen the correct blog. Without much ado, let’s discuss in detail how you can optimize the performance of Vue js large application structure. It’s essential first to understand the Vue js app architecture. By knowing its importance, we can be aware of how crucial it is, and we would start taking it more seriously. So, let’s look at why there’s a need to optimize your large scale application. Please keep in mind that optimization of any application is essential, but as this blog concerns, we’ll be discussing it.
  • 8. No programmer will ever want that even after coding thousands of lines, users don’t want to spend time on the application because of the time it takes to perform user actions. Product owners around the world develop products for users, and these users are mainly concerned with their smooth interactions. It does not concern the end- users how much effort programmers have invested in Vue JS app architecture if they are not satisfied with Vue js speed and efficiency. So, yes, that is why it becomes mandatory criteria to optimize the performance that will eventually satisfy the end-users’ needs.
  • 10. Let’s look at how Vue js works and the significant reasons behind poor Vue performance. The reasons for slowing down the Vue performance depend upon your Vue js app structure. For example, one of the significant reasons behind poor performance in Vue jS Single Page Applications (SPAs) may vary from the VueJS projects dealing with Server Side Rendering (SSR). The primary and foremost reason any developer can think of whether the application is SPA or having SSR is bundle size. The larger the bundle size slower the Vue js performance. Thus we can conclude that bundle size is inversely proportional to the application performance.
  • 11. Not using third-party libraries wisely Overlooking Code Splitting and Lazy Loading Unwanted hits to API requests Not structuring JS and CSS files properly Some of the common reasons behind Vue js large application- Before discussing how to reduce the bundle size, let’s see how to check the size of the Vue js and Vue js enterprise application’s bundle size.
  • 12. How to Check the Bundle Size of your VueJS app?
  • 13. I’ll be showing you two ways to check the bundle size of the Vue js application. 1. To generate a report Generating reports give you a visual description of the sizes of various packages used. Further, you can figure out to replace any package which takes more space than expected. You can use the command build – report for generating the report of your application. Keep in mind that this command will build a report of the application which has installed webpack- bundle-analyzer. After running the command as mentioned above, open the package.json file and add this –
  • 14. "build-report": "vue-cli-service build -- report" And then execute this – npm run build-report After performing all this, a file named – report.html will be created in the dist folder.On opening that file, you’ll observe this –
  • 15. 2. Run command – npm run build You will see something like this image. Now, after finding the bundle size, the struggle is to reduce that. Without further ado, let’s proceed and explore the ways of Vue.js app performance optimization.
  • 17. Here are some VueJS performance tips that you can implement to optimize the performance of Vue.js application. As per the name, Lazy Loading in Vue js is the method of loading the modules in your application lazily, i.e., when the user actually needs that module. Most of the time, there’s no need to load all the modules from the JavaScript bundle whenever users visit the website. There are some components having modals and tooltips that can be loaded when needed. You won’t see the result if you’re dealing with two or three modals or tooltips but, assume that you have an extensive Vue application with so many modals and tooltips; loading them at a time can lessen your performance. 1. Lazy Loading in Vue js
  • 18. It is not at all worthy of loading the entire bundle every time the page loads. Thus, it loading helps you to divide the bundle and load them when it is used. This way, it saves time by not downloading and parsing the unnecessary code. To check the actual JavaScript code being used in the website – 1. Click devtools 2. cmd + shift + p 3. Type coverage 4. Click record The URLs with red highlights are not in use and can be loaded lazily. By taking advantage of lazy loading, you can reduce the bundle size by 60%.
  • 19. This was about what and why we should load components and modules lazily in large scale application; let’s explore How to enforce it. We can use Webpack Dynamic Imports rather than regular imports to separate the chunk of modules that have to be loaded lazily. // demo.js const Demo = { testDemo: function () { console.log("This is just a demo!") } } export default Demo // app.js import Demo from './demo.js' Demo.testDemo() This is how you import your JavaScript files, right?
  • 20. It will add the file demo.js as the node to app.js in its dependency graph and bundle it together by importing it in such a manner. So, whenever the bundle is loaded, demo.js will be loaded irrespective of its need. But, what if we want to load demo.js only as of the response of some user actions. In such a case, we will implement dynamic importing, telling the application to download this module only when needed.
  • 21. Here is the modification was done to the above code for executing dynamic imports for testing Vue.js app // app.js const getDemo = () => import('./demo.js') // later when some user action tasks place as hitting the route getDemo() .then({ testDemo } => testDemo())
  • 22. So, you can notice that instead of importing the Demo module directly, I have declared a function which indeed returns the import() function. And this is what we call dynamic importing, due to which the webpack will know that it has to keep this module in a separate file. The function getDemo(), which contains the dynamic import, returns the Promise. We are basically cutting off the node ( here Demo ) from the dependency graph and later downloading it when needed ( such as route changing or clicking ). Keep in mind that the modules imported in Demo.js will also be isolated from the bundle. Lazy Loading in Vue js is one of the best practices to reduce bundle size and optimize performance. Develop a habit of knowing which modules you don’t need unless there’s an explicit user action and download them lazily for better performance.
  • 23. Assume you have to develop a small VueJS website with two web pages – Dashboard and Contact. Even for these two pages, you need to implement vue-router in your project. // routing.js import Dashboard from './Dashboard.vue' import Contact from './Contact.vue' const routes = [ { path: '/', component: Dashboard } { path: '/contact, component: Contact } ] 2. Code splitting based on Routes Your routing file may look like this-
  • 24. Due to this standard coding method, the components – Dashboard and Contact ( with lodash)- will be downloaded even when the user visits another page, where we neither want to download Dashboard nor Contact. It is because we have both the routes in the same bundle. You might think what is a big deal with downloading two extra pages. But, this matters when you’re dealing with large applications with huge bundles. To avoid this unnecessary downloading of the components, we will use split the code.And for that, we will be having separate bundles for different routes which we follow the technique of dynamic imports. Rather than importing the components directly, you will now pass the dynamic routes. Let’s see how to achieve this.
  • 25. // routing.js const routes = [ { path: '/', component: () => import('./Dashboard.vue') } { path: '/contact, component: () => import('./Contact.vue') } ] By following this practice, you can decrease your bundle size to its half! But for that, you need to be sure which components can be used with dynamic imports. Believe me, such vue js practice will help your application to be more performant.
  • 26. Let’s move ahead and dive deeper into Vue js prefetch components is a technique to download the resources before the user requests the page. For example, if you are sure that most users will visit the product page from the category page, you can think of prefetching the product page. You need to keep in mind that only after the initial render prefetching can take place. Another benefit of prefetching is that it removes the unwanted consequences caused due to lazy loading without affecting performance. 3. Vue js Prefetch components
  • 27. For its implementation you just need to add < link rel="prefetch" href="url" /> tag. Simple, right? But the case is different when dealing with webpack, which generates the bundle names based on the module’s order. Luckily, webpack has magic comments to prefetch easily. Magic comments are comments affecting the build’s process. We need to use – /* webpackPrefetch: true */ for prefetching the modules. Just keep it in your dynamic imports as displayed below – components: { ModalView: () => import(/* webpackPrefetch: true */ './ModalView.vue') } While executing the code, webpack will search for magic comments and add < link rel="prefetch" url="resource-url" /> in the head section.
  • 28. < link rel="prefetch" href="path-to-chunk- with-modal-view" /> Whenever the user requests the ModalView module, it will be prefetched already and accessible instantly.
  • 30. When you check how much is your bundle size and are surprised if it crosses the ideal number, it’s not always because of what you code; so many times, the reason is the usage of loaded third-party libraries. Yes, we all use third-party libraries without knowing their impact on our application’s performance. Our code might be a tiny part of the bundle size. You can use bundlephobia to know how do different libraries can affect performance. You just need to add the Vuejs library name to this fantastic website, and you’ll gain a lot of knowledge related to your website- data. For example, I’ve used lodash library, and here is the information.
  • 31. Isn’t this awesome to know more about the libraries and their effects on the performance. If you want to know which Vue js libraries have more impact on your VueJS application, then you can click here to scan your package.json. Apart from this, I have already made clear the various methods for analyzing the bundle size.
  • 32. Why do I want to use the library? Do I need the whole library for my purpose? What is the impact of the library I chose? Do I have a performance-friendly way of using the library? Let’s take a look at how I deal when I’m choosing a Vue library. If I need some functions for my program for which I’ll like to install lodash library.But, as I’m aware of how much lodash would cost to the performance so rather than importing the whole library, I’ll just import the functions, like this- Before choosing any library, ask these questions to yourself;
  • 33. import isEmpty from 'lodash/isEmpty` Trust me, making such small changes in different libraries will create a more significant and noticeable impact. So far, we have dealt with the bundle size of VueJS large scale application and VueJS performance tips for the same. For optimizing performance, reducing bundle size is not the only solution. It’s essential to reuse some of the assets so that users don’t have to wait. In our next step, let’s see how to use the browser cache for reusing. Using Browser Cache We have discussed enough regarding bundle size; in this last step, we will focus on caching the data.
  • 34. Caching is a technique of storing selective data to access it quickly when requested. The browser preserves the data in the memory cache until the browser is not closed. You can observe this by yourself. Open your developer tool and select the Network tab. Visit any website and reload it few times. You’ll notice that some of the static files like CSS, images, javascript, and HTML will have a memory cache, as shown below. This means that such files are being served from the memory cache.
  • 35. As browsers are handling caches pretty well by themselves. You might think, what can we add to this? So, you just need to figure out which parts of your VueJS app structure change rarely compared to others so that we can cache those parts. Assume the structure of your project to be like this- main.[hash].js – root component of your project common.[hash].js – common components of your project dashboard.[hash].js – dashboard specific components contact.[hash].js – contact specific components
  • 36. The part that concerns us is common. [hash].js. We can have all the dependencies here, which are not likely to change often, and we can further use it for caching the data. By separating such components, you are saving your users’ time. You can visit here to read more about how to separate the dependencies into different parts. So, this was all about how to optimize your VueJS app performance. I hope that all your questions and queries are answered through this blog.
  • 37. No matter how large scale application you have developed, it requires to be optimized at some point. If you are looking to hire VueJS developer for optimizing your Vue.js app to satisfying your end-users, then you are just one click away. Get in touch with Bacancy Technology to experience one-of- a-kind Vue js best practices and Vue.js application development services. We are globally acknowledged for offering advanced vue.js application architecture. Conclusion