SlideShare uma empresa Scribd logo
1 de 90
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

Mais conteúdo relacionado

Mais procurados

Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web Apps
Rasheed Waraich
 
What’s new in LightSwitch 2013?
What’s new in LightSwitch 2013?What’s new in LightSwitch 2013?
What’s new in LightSwitch 2013?
Robert MacLean
 

Mais procurados (19)

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

Semelhante a Performance optimization of vue.js apps with modern js

Web Frameworks of the Future
Web Frameworks of the FutureWeb Frameworks of the Future
Web Frameworks of the Future
elliando dias
 

Semelhante a Performance optimization of vue.js apps with modern js (20)

Filip Rakowski "Web Performance in modern JavaScript world"
Filip Rakowski "Web Performance in modern JavaScript world"Filip Rakowski "Web Performance in modern JavaScript world"
Filip Rakowski "Web Performance in modern JavaScript world"
 
Web Frameworks of the Future
Web Frameworks of the FutureWeb Frameworks of the Future
Web Frameworks of the Future
 
Long life to vagrant… Vagrant is dead
Long life to vagrant… Vagrant is deadLong life to vagrant… Vagrant is dead
Long life to vagrant… Vagrant is dead
 
"You’re probably using Lighthouse wrong: How do we misuse the most common too...
"You’re probably using Lighthouse wrong: How do we misuse the most common too..."You’re probably using Lighthouse wrong: How do we misuse the most common too...
"You’re probably using Lighthouse wrong: How do we misuse the most common too...
 
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
FFWD.PRO - It's not you, It's me (or how to avoid being coupled with a Javasc...
 
Refactoring to Go modules: why and how
Refactoring to Go modules: why and howRefactoring to Go modules: why and how
Refactoring to Go modules: why and how
 
Phonegap 1.0
Phonegap 1.0Phonegap 1.0
Phonegap 1.0
 
Web Components: The Future of Web Development is Here
Web Components: The Future of Web Development is HereWeb Components: The Future of Web Development is Here
Web Components: The Future of Web Development is Here
 
Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
Selje_Amazing VFP2C32 Library.pdf
Selje_Amazing VFP2C32 Library.pdfSelje_Amazing VFP2C32 Library.pdf
Selje_Amazing VFP2C32 Library.pdf
 
Introduction to Progressive Web Apps / Meet Magento PL 2018
Introduction to Progressive Web Apps / Meet Magento PL 2018Introduction to Progressive Web Apps / Meet Magento PL 2018
Introduction to Progressive Web Apps / Meet Magento PL 2018
 
The Big Cloud native FaaS Lebowski
The Big Cloud native FaaS LebowskiThe Big Cloud native FaaS Lebowski
The Big Cloud native FaaS Lebowski
 
Workshop: Introduction to Web Components & Polymer
Workshop: Introduction to Web Components & Polymer Workshop: Introduction to Web Components & Polymer
Workshop: Introduction to Web Components & Polymer
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
Pain Driven Development by Alexandr Sugak
Pain Driven Development by Alexandr SugakPain Driven Development by Alexandr Sugak
Pain Driven Development by Alexandr Sugak
 
"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG
"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG
"Will Git Be Around Forever? A List of Possible Successors" at UtrechtJUG
 
Ionic - Revolutionizing Hybrid Mobile Application Development
Ionic - Revolutionizing Hybrid Mobile Application DevelopmentIonic - Revolutionizing Hybrid Mobile Application Development
Ionic - Revolutionizing Hybrid Mobile Application Development
 
Encode polkadot club
Encode polkadot club  Encode polkadot club
Encode polkadot club
 
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
JsDay - It's not you, It's me (or how to avoid being coupled with a Javascrip...
 
Enhance SharePoint with Responsive Web Design
Enhance SharePoint with Responsive Web DesignEnhance SharePoint with Responsive Web Design
Enhance SharePoint with Responsive Web Design
 

Último

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 

Último (20)

APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
Tadepalligudem Escorts Service Girl ^ 9332606886, WhatsApp Anytime Tadepallig...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Call girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girlsCall girls Service in Ajman 0505086370 Ajman call girls
Call girls Service in Ajman 0505086370 Ajman call girls
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 

Performance optimization of vue.js apps with modern js

Notas do Editor

  1. How many of you think performance is important?
  2. 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.
  3. 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
  4. Given all this number we can assume a simple equation. Speed equals money. Do you agree?
  5. Now when I hope you’re convinced you how important web performance is let’s find main factors affecting it
  6. 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.
  7. Next JavaScript engine needs to parse it. Again the bigger file is - the longer it takes.
  8. 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.
  9. 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.
  10. Let’s see what problems we can encounter by creating simple app
  11. It usually starts like this. An entry point with Vue attached and a root component. But over time the application grows
  12. We almost certainly will add a Vue-router. Following this we will add some routes, probably another 3rd party libs.
  13. Our initially downloaded JS bundle will grow with every module we add
  14. As we remember speed equals money so does it mean that more features equals less money?
  15. 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
  16. 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
  17. 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
  18. This is why webpack has feature called code splitting. It allows you to split your code into different bundles and load them on demand.
  19. Lazy loading is just loading this code splitter chunks on demand. So we are cutting some modules and loading them when they are needed
  20. 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.
  21. By dynamically importing routes we are making sure that only the visited route will be downloaded
  22. Code-splitter JS bundles generated by webpack will look like this.We have three bundles instead of one big file
  23. If you are using Nuxt you have this feature out of the box
  24. So rule number one… Per-route code splitting will give you more than any other lazy code splitting technique but we can do more
  25. There are still many things that are not needed right after user enters your website and can be loaded lazily
  26. Like popups
  27. Sidebars or any other off-screen components
  28. So rule number 2
  29. 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
  30. It appears that most of the 3rd party libs can also be loaded lazily.
  31. And the syntax is the same. Import function returns a promise with the lazily loaded lib
  32. When speaking about 3rd party libs there is a common approach to keep all of node modules in vendor bundle.
  33. 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
  34. You’ll probably say ‚Hey Filip it leads to code duplication aren;’t vendor bundles meant to prevent it?’
  35. What if we will have loads imported in two routes. How to deal with this duplication?
  36. Now the shared modules will be bundled into a separate file and therefore downloaded only once
  37. 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
  38. There is a great website that can help you with choosing appropriate libraries - bundle phobia
  39. It will give you all the information on how adding some particular library will affect your apps performance
  40. what is even better - it will also suggest you alternatives so you can really choose the best option
  41. 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
  42. We can reduce the number of network requests by making use of assets that we already downloaded
  43. And we can use SW for this. They work as a proxy between your client web app and server
  44. We are sending request to the service worker which proxies it to the network
  45. 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.
  46. You can either install Vue-cli PWA plugin for this
  47. ..or Nuxt PWA module
  48. In both cases you will see cached data under application tab of your devtools. Of course you can configure it as you wish
  49. We can make use of prefetching
  50. Which is just downloading assets before they are needed
  51. So rule number 5
  52. 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
  53. Or use more general solutions with regular expressions
  54. If you are using Vue-cli 3 it’s prefetching code-splitter chunks out of the box
  55. If you are using Vue-cli 3 it’s prefetching code-splitter chunks out of the box
  56. Ok we learned a lot about performance optimization but it’s equally important to know where to optimize and measure our results.
  57. You can use devtools „coevrage” tool to see how much of the shipped code was actually executed
  58. You can also use Webpack Bundle Analyzer to actually see the size of your modules. This one is a must-have.
  59. …and instalation is extremely easy
  60. You can use ‚bundlesize’ package to make sure that you are not exceeding the reasonable size of the package.
  61. ..it also has a very nice GitHub integration
  62. And you can use import cost plugin to keep track of size of your imports