SlideShare a Scribd company logo
Performance Optimization of
Vue.js Apps with modern JS
Filip Rakowski
@filrakowski
Filip Rakowski
Co-founder
Frontend Developer
Community partner
@filrakowski
Let’s talk about Performance!
*but not rendering performance, it’s a huge topic and they gave me only 25 minutes ;(
@filrakowski
Why performance is important?
@filrakowski
@filrakowski
2.2 sec load time reduction resulted in 15.4%
more downloads
Firefox
@filrakowski
1s slowdown resulted in 11% less page views
Aberdeen Group
@filrakowski
2 sec delay resulted in 4.3% loss in revenue
per visitor and 3.75% reduction in clicks
Bing
@filrakowski
cutting page load time half resulted in 13%
increase in sales
AutoAnything
@filrakowski
SPEED = MONEY
@filrakowski
What influences loading time performance?
@filrakowski
Request /
Response
@filrakowski
Request /
Response
Parsing
@filrakowski
Request /
Response
Parsing Execution
@filrakowski
Request /
Response
Parsing Execution
@filrakowski
Let’s make an app!
@filrakowski
main.jsApp.vue Vue
@filrakowski
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router app.js
App.vue
every new module or library
=
bigger bundle
@filrakowski
bigger bundle
=
longer download
@filrakowski
bigger bundle
=
longer parsing
@filrakowski
bigger bundle
=
longer execution
@filrakowski
SPEED = MONEY
@filrakowski
MORE FEATURES = LESS MONEY?
@filrakowski
@filrakowski
How webpack bundling works?
@filrakowski
Dependency graph is a graph of modules in
your application. Starting from entry point
webpack is recursively adding all imported
modules to the graph and bundles them into
(usually) one file.
@filrakowski
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router
App.vue
app.js
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router app.js
App.vue We might not
need this!
Code splitting allows you to split your code
into various bundles. You can think about this
as deferring a piece of your dependency
graph to be loaded later.
@filrakowski
Lazy loading loading chunk of code on demand
usually as a response to user action.
@filrakowski
Dynamic import
@filrakowski
@filrakowski
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router app.js
App.vue
home.js
about.js
Nuxt is doing per-route code-splitting out of the box!
@filrakowski
Rule #1 - Split your code per route
@filrakowski
What else we don’t need on initial download?
@filrakowski
@filrakowski
@filrakowski
Rule #2 - Load off-screen components lazily
@filrakowski
@filrakowski
You can use v-if to lazily
load off-screen components
What else?
@filrakowski
Rule #3 - Load non-critical libraries lazily
@filrakowski
@filrakowski
Rule #4 - Avoid bundling all 3rd party libs into
one file. It’s an anti-pattern.
@filrakowski
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router vendor.js
App.vue
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router vendor.js
App.vue
We might not
need this!
What about code duplication?
@filrakowski
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router app.js
App.vue
home.js
about.js
Lodash
main.jsrouter.js Vue
@filrakowski
Home.vue
About.vueLodash
vue-router app.js
App.vue
home.js
about.js
Lodash
@filrakowski
Rule #5 - Choose your libraries carefully and
try to find smaller equivalents if possible
@filrakowski
@filrakowski
@filrakowski
@filrakowski
Request /
Response
Parsing Execution
@filrakowski
Rule #5 - Make use of cache for static assets
@filrakowski
Service workers essentially act as proxy
servers that sit between web applications, the
browser, and the network (when available).
They can be used to serve network responses
from cache instead of a network.
@filrakowski
Service
Worker
Network
@filrakowski
Client app
Service
Worker
Network
@filrakowski
Client app
Cache
If asset was previously
downloaded
If asset is not in cache
or needs to be „fresh”
Vue CLI PWA plugin
@filrakowski
@filrakowski
Nuxt PWA module
@filrakowski
@filrakowski
@filrakowski
What else we can do?
@filrakowski
Prefetching downloading assets before they’re
requested.
@filrakowski
Rule #6 - Prefetch lazily loaded resources
@filrakowski
@filrakowski
More general options
webpack precachePlugin
workbox-webpack-plugin
@filrakowski
Vue-cli 3 is prefetching lazy chunks out of the box!
@filrakowski
Don’t forget about compression, minification and other
stuff that webpack and DevOps will do for you
@filrakowski
Measuring and analyzing
@filrakowski
#1 Dev tools “coverage” tool
@filrakowski
@filrakowski
CMD + Shift + P “Coverage”
@filrakowski
Everything marked with red should probably be loaded lazily
#2 Webpack bundle analyzer
@filrakowski
@filrakowski
@filrakowski
#2 ‘bundlesize’ package
@filrakowski
@filrakowski
@filrakowski
#3 VS Code ‘Import cost’ plugin
@filrakowski
@filrakowski
Thank you!
If you already forgot something - don’t worry.
I’ll share the slides :)
@filrakowski

More Related Content

PPTX
Vue Storefront MUG
PPTX
PWA basics for developers
PDF
Building resuable and customizable Vue components
PPTX
Vue Storefront Basics
PPTX
Vue storefront London PWA meetup
PPTX
Maintainable design
PPTX
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
PPTX
[DevDay2019] Micro Frontends Architecture - By Thang Pham, Senior Software En...
Vue Storefront MUG
PWA basics for developers
Building resuable and customizable Vue components
Vue Storefront Basics
Vue storefront London PWA meetup
Maintainable design
“Micro Frontends”- You Keep Using That Word, I Don’t Think It Means What You ...
[DevDay2019] Micro Frontends Architecture - By Thang Pham, Senior Software En...

What's hot (19)

PPTX
10 top web development frameworks (new version 21 11)
PPTX
Aeternity Blockchain - Ecosystem & Devtools [2019]
PPTX
Architecture & Workflow of Modern Web Apps
PPTX
What’s new in LightSwitch 2013?
PPTX
Micro frontends
PPTX
Windows 8
PPTX
Visual Studio: The best tool for web developers.
PPTX
Micro-Frontends JSVidCon
PPTX
Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...
PPTX
Fronted development trends - past, present and the future
PPTX
Web Development and Web Development technologies - Temitayo Fadojutimi
PDF
Magento 2 Module in 50 Minutes
PDF
How To be a Backend developer
PPTX
Full stack web development
PPT
Joomla as a mobile App backend - ideas, examples and experiences
PDF
PWA for PHP Developers
PDF
What Web Framework To Use?
PDF
Progressive Web Apps / GDG DevFest - Season 2016
PPTX
Continuous workflow for a large react native app - mobile at wix
10 top web development frameworks (new version 21 11)
Aeternity Blockchain - Ecosystem & Devtools [2019]
Architecture & Workflow of Modern Web Apps
What’s new in LightSwitch 2013?
Micro frontends
Windows 8
Visual Studio: The best tool for web developers.
Micro-Frontends JSVidCon
Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...
Fronted development trends - past, present and the future
Web Development and Web Development technologies - Temitayo Fadojutimi
Magento 2 Module in 50 Minutes
How To be a Backend developer
Full stack web development
Joomla as a mobile App backend - ideas, examples and experiences
PWA for PHP Developers
What Web Framework To Use?
Progressive Web Apps / GDG DevFest - Season 2016
Continuous workflow for a large react native app - mobile at wix
Ad

Similar to Performance optimization of vue.js apps with modern js (20)

PDF
Filip Rakowski "Web Performance in modern JavaScript world"
PDF
How to optimize the performance of vue js large application structure
PPT
Smarr Oscon 2007
PPT
Os Smarr
PDF
The Journey of a Pixel in a React Application
PDF
Scalable Front-end Development with Vue.JS
PDF
VueJS in Action
PDF
Using React for the Mobile Web
PDF
Front-End Performance Checklist 2020
PDF
VueJS Best Practices
PDF
Progressive Javascript: Why React when you can Vue?
PPT
High Performance Ajax Applications 1197671494632682 2
PPT
High Performance Ajax Applications
PPT
High performance java script why everything youve been taught is wrong
PDF
Production optimization with React and Webpack
PDF
How we improved performance at Mixbook
PDF
Bringing the JAMstack to the Enterprise
PDF
10 Web Performance Lessons For the 21st Century
KEY
A rough guide to JavaScript Performance
PDF
Thinking Beyond Core Web Vitals - Web performance optimisations for the harsh...
Filip Rakowski "Web Performance in modern JavaScript world"
How to optimize the performance of vue js large application structure
Smarr Oscon 2007
Os Smarr
The Journey of a Pixel in a React Application
Scalable Front-end Development with Vue.JS
VueJS in Action
Using React for the Mobile Web
Front-End Performance Checklist 2020
VueJS Best Practices
Progressive Javascript: Why React when you can Vue?
High Performance Ajax Applications 1197671494632682 2
High Performance Ajax Applications
High performance java script why everything youve been taught is wrong
Production optimization with React and Webpack
How we improved performance at Mixbook
Bringing the JAMstack to the Enterprise
10 Web Performance Lessons For the 21st Century
A rough guide to JavaScript Performance
Thinking Beyond Core Web Vitals - Web performance optimisations for the harsh...
Ad

Recently uploaded (20)

PPTX
Digital Literacy And Online Safety on internet
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Funds Management Learning Material for Beg
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Testing WebRTC applications at scale.pdf
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Introduction to Information and Communication Technology
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
DOCX
Unit-3 cyber security network security of internet system
Digital Literacy And Online Safety on internet
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Cloud-Scale Log Monitoring _ Datadog.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
522797556-Unit-2-Temperature-measurement-1-1.pptx
Funds Management Learning Material for Beg
Unit-1 introduction to cyber security discuss about how to secure a system
QR Codes Qr codecodecodecodecocodedecodecode
WebRTC in SignalWire - troubleshooting media negotiation
Testing WebRTC applications at scale.pdf
introduction about ICD -10 & ICD-11 ppt.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Paper PDF World Game (s) Great Redesign.pdf
Module 1 - Cyber Law and Ethics 101.pptx
presentation_pfe-universite-molay-seltan.pptx
Introduction to Information and Communication Technology
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Design_with_Watersergyerge45hrbgre4top (1).ppt
Job_Card_System_Styled_lorem_ipsum_.pptx
Unit-3 cyber security network security of internet system

Performance optimization of vue.js apps with modern js

Editor's Notes

  • #4: How many of you think performance is important?
  • #5: For those who did not raised their hands I will pretend that I’m smart and show some numbers to prove my point that web performance is extremely important.
  • #6: First of all as you can see only one second of waiting is enough for the user to make a mental context switch and potentially leave our website. Now let’s see how performance affects other numbers
  • #11: Given all this number we can assume a simple equation. Speed equals money. Do you agree?
  • #12: Now when I hope you’re convinced you how important web performance is let’s find main factors affecting it
  • #13: When we want some resource we need to request it and wait for resource. The bigger file is - the longer it takes to download it.
  • #14: Next JavaScript engine needs to parse it. Again the bigger file is - the longer it takes.
  • #15: Once parsing is finished and our JS engine created a nice AST that browser can work with it’s time to execute the code and guess what - the more code it’s to execute the longer it takes.
  • #16: Ok so it looks like the main factor influencing loading performance is file size. As a frontend developers we mostly can optimize the execution and parsing phase but we will see later that there are some things that we can do to improve response time. For now let’s focus on the area that we certainly can fully control.
  • #17: Let’s see what problems we can encounter by creating simple app
  • #18: It usually starts like this. An entry point with Vue attached and a root component. But over time the application grows
  • #19: We almost certainly will add a Vue-router. Following this we will add some routes, probably another 3rd party libs.
  • #20: Our initially downloaded JS bundle will grow with every module we add
  • #24: As we remember speed equals money so does it mean that more features equals less money?
  • #26: As you probably guessed it doesn’t To understand how to solve performance issues with growing bundle we need to understand how this bundle is constructed
  • #28: It appears that web pack under the hood is creating something called dependency graph. It’s just recursively checks the imports in JS modules and adds them to the graph starting from your entry point. To better understand this process lets see an example
  • #35: The problem with bundling all modules into one file is that we might not need some of the modules depending on current state of the application
  • #36: This is why webpack has feature called code splitting. It allows you to split your code into different bundles and load them on demand.
  • #37: Lazy loading is just loading this code splitter chunks on demand. So we are cutting some modules and loading them when they are needed
  • #38: We can tell webpack which parts of the code it should split by doing a dynamic import. Instead of a regular import dynamically imported module is an entry point for a completely new bundle. The bundle will be lazily loaded ONLY when this function is invoked.
  • #39: By dynamically importing routes we are making sure that only the visited route will be downloaded
  • #40: Code-splitter JS bundles generated by webpack will look like this.We have three bundles instead of one big file
  • #41: If you are using Nuxt you have this feature out of the box
  • #42: So rule number one… Per-route code splitting will give you more than any other lazy code splitting technique but we can do more
  • #43: There are still many things that are not needed right after user enters your website and can be loaded lazily
  • #44: Like popups
  • #45: Sidebars or any other off-screen components
  • #46: So rule number 2
  • #47: You can use v-if to conditionally load offscreen compoennts. V-if not true -> no render - no invocation - no download. It’s a great way to conditionally load components
  • #49: It appears that most of the 3rd party libs can also be loaded lazily.
  • #50: And the syntax is the same. Import function returns a promise with the lazily loaded lib
  • #51: When speaking about 3rd party libs there is a common approach to keep all of node modules in vendor bundle.
  • #53: Don’t do this. It’s much better to k keep 3rd party libs in route bundles or even better load them lazily whenever it’s possible. Otherwise users will download redundant code
  • #54: You’ll probably say ‚Hey Filip it leads to code duplication aren;’t vendor bundles meant to prevent it?’
  • #55: What if we will have loads imported in two routes. How to deal with this duplication?
  • #57: Now the shared modules will be bundled into a separate file and therefore downloaded only once
  • #58: Staying in the 3rd party libs topic there are tons of them and not all of them are good for your use case, or good overall so choose them carefully
  • #59: There is a great website that can help you with choosing appropriate libraries - bundle phobia
  • #60: It will give you all the information on how adding some particular library will affect your apps performance
  • #61: what is even better - it will also suggest you alternatives so you can really choose the best option
  • #62: Previously I mentioned that as a frontend devs we don’t have influence on how fast the server responds but it turns out that there are some things that we can do to improve this part of the process
  • #63: We can reduce the number of network requests by making use of assets that we already downloaded
  • #64: And we can use SW for this. They work as a proxy between your client web app and server
  • #65: We are sending request to the service worker which proxies it to the network
  • #66: But it can also proxy this request to the cache if asset was previously downloaded and respond almost instantly. Service Worker cache persists even when browser has been closed.
  • #67: You can either install Vue-cli PWA plugin for this
  • #70: ..or Nuxt PWA module
  • #71: In both cases you will see cached data under application tab of your devtools. Of course you can configure it as you wish
  • #72: We can make use of prefetching
  • #73: Which is just downloading assets before they are needed
  • #74: So rule number 5
  • #75: We can explicitly tell which chunks of code we want to prefetch with web pack magic comments that will dynamically add prefetch link to the head of our application
  • #76: Or use more general solutions with regular expressions
  • #77: If you are using Vue-cli 3 it’s prefetching code-splitter chunks out of the box
  • #78: If you are using Vue-cli 3 it’s prefetching code-splitter chunks out of the box
  • #79: Ok we learned a lot about performance optimization but it’s equally important to know where to optimize and measure our results.
  • #80: You can use devtools „coevrage” tool to see how much of the shipped code was actually executed
  • #83: You can also use Webpack Bundle Analyzer to actually see the size of your modules. This one is a must-have.
  • #85: …and instalation is extremely easy
  • #86: You can use ‚bundlesize’ package to make sure that you are not exceeding the reasonable size of the package.
  • #88: ..it also has a very nice GitHub integration
  • #89: And you can use import cost plugin to keep track of size of your imports