Remove unused code Google Page Speed and others errors
Asked Answered
J

1

6

Google Page Speed report me here an error that I can't understand.

Remove unused code I use all the javascript that Google Page Speed says, in fact vendor.js is the main script of the project. Compiled and unified with Webpack and Laravel.

Then why does Google Page Speed say I don't use these scripts? Before I uploaded the lazysizes plugin I didn't get any of this.

On the other hand, the website loads quickly. I think Google Page Speed is very unreliable.

Juvenal answered 28/5, 2020 at 12:49 Comment(0)
G
6

Remove Unused Code is explained here

It isn't that the entire script isn't used, it is that large portions of the script are not used for initial page render.

Google is encouraging you to split your JavaScript into essential code to render the page / initialise components and then put everything else in separate files that are loaded later.

It is also encouraging you to purge any redundant JavaScript from those files.

This is to save Kb being downloaded, as well as to save on JavaScript parsing and compilation time by the V8 engine (important for slower processors in low-end mobile phones).

To check this yourself open developer tools in Google Chrome and open the 'coverage' window. Press record and see how much of each script is not used. On your site around 60% of the JS downloaded is not used initially, you should push the 40% you use down the wire first and load the rest after everything else has loaded. (this is extremely difficult unless you build for it in the first place, do the best you can!).

As for your site being fast - it loads fully in 7 seconds for me on my PC with a leased line (so about as fast as you can get, albeit I am in the UK so that may add a second overall)

On a simulated 4G connection with a 4x CPU slowdown (to simulate a mobile phone with limited processing power that is not connected to WiFi) your site takes nearly 18 seconds to complete loading with a total page weight of 2.5Mb (zipped - its 5.5Mb unzipped).

This is the test that PSI performs on the 'Mobile' tab (4x slowdown and 4G simulation)

Page weight is one of your biggest problems along with the volume of JavaScript the site uses, those are the areas to focus on. Also try to reduce the number of requests if possible, you have 149 different network requests and only a maximum of 8 at a time can be downloaded simultaneously.

While PSI is only a tool it does produce fairly accurate results, the "Field Data" at the top is real world data from browsers so I would pay particular attention to that, in particular "First Contentful Paint (FCP)" where 40% of your users are experience an average or slow time.

Gullet answered 28/5, 2020 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.