Lighthouse suggests that I need to remove the unused javascript from the third party javascript library say index.js
. It is okay for this particular library to load after few 10 seconds once the page is loaded. So I used the SetTimeout
method to do that but I don't think that is the right approach to do it.
Once I do that, lighthouse does not complain about unused javascript from this library and improves the score, but I am worried that in production Google measure the overall performance of the page from the moment page loads to the moment user leaves the page. So in that sense, the unused javascript is never removed and just delayed for the execution. People also suggested that lazy loading JS on user events will help but in our the case mentioned above, the JS should load automatically.
I am basically looking for the suggestion to:
- How to handle the JS libraries that I can't get rid of and which has lot of unused code in the page?
- Is
setTimeout
good solution for the above case? - Is my understanding of performance calculation by Google correct (in production environment) although it does not show unused JS after delaying for 10seconds?
I would be more than happy to get the answers.