Performance matters and probably everyone hears that 1-second delay in page response can result in a 7% reduction in conversion, translating it to sales, potentially you are going to lose $2.5 million every year if your store is making $100.000 per day.
Even the best-optimized back-end solution can be ruined by the bunch of JavaScript libraries or even just not optimised images. It’s really easy to forget about front-end performance or let you clients ruin it just by adding unoptimized content and tons of tracking scripts.
I’ll show you a way to easily measure the Magento 2 front-end performance and how to find and eliminate bottlenecks. The talk will also cover common mistakes and show how different configuration options will affect page load and user experience.
1. #MM17PL
Magento 2 Front-end
performance tips & tricks
Definitely not a talk about replacing front-end stack
Bartek Igielski
Lead Front-end Developer at Snowdog
@igloczek
5. #MM17PL
How to measure performance?
Lighthouse
A tower or other structure tool containing a beacon
light to warn or guide ships at sea developers.
https://github.com/GoogleChrome/lighthouse
7. #MM17PL
How it works?
• Run on clean Chrome instance
• Emulate Nexus 5X size
• CPU throttling is enabled to emulate smartphone performance
• Network is throttled to slow 3G
8. #MM17PL
1. "Audits" panel in Chrome Developer Tools
But… Currently it’s outdated (2.0.0 vs 2.4.0) so test
results are not always accurate.
2. Chrome extension - possibly easiest way
3. Node CLI - most powerful way
How to use Lighthouse?
20. #MM17PL
Inline CSS
To ensure that browsers start rendering your page as quickly as
possible, it’s become a common practice to collect all of the CSS
required to start rendering the first visible portion of the page
(known as “critical CSS” or “above-the-fold CSS”) and add it inline
in the <head> of the page, thus reducing roundtrips.
You can force your page to render meaningful content within 1.5s
21. #MM17PL
Generate Critical CSS and inline it
Best way, but not easy with M2 styles codebase
Add loader to hide unsettled content
Easiest way, but without any positive performance
impact
Inline CSS
27. #MM17PL
Low Quality Image
Placeholders
1. Initially load the page with low quality images
2. Once the page loaded (e.g. in the onload event),
replace them with the full quality images
Possible improvements to lazy-loading model
https://www.guypo.com/introducing-lqip-low-quality-image-placeholders/
44. #MM17PL
More possibilities…
1. Parse rendered page, take all script tags and move to
the end of the body. This will let us to remove blocking
JS from the head and make page to render way faster
than now.
2. Use HTTP/2 Push to load heavies files like: jQuery UI lib,
jQuery lib, stylesheets etc. (for now Apache only)
3. Use Brotli or Zopfli compression format (lossless
compression algorithms like a Gzip)
4. Service workers
45. #MM17PL
Further reading
Front End Performance Checklist 2017
https://www.smashingmagazine.com/2016/12/front-end-performance-
checklist-2017-pdf-pages/
https://github.com/SnowdogApps/magento2-theme-performance
46. #MM17PL
Q & A Time!
Let’s stay in touch
Twitter: @igloczek
Blog: iglo.tech
bartek.igielski@snow.dog