Our client wants us to improve the performance of the solution and used https://developers.google.com/speed/pagespeed/insights/ to test it. Now "Google Insights" says:
Your page has 2 blocking script resources. This causes a delay in rendering your page.
Remove render-blocking JavaScript:
https://www.example.com/api/utils/libs/jsnlog.min.js
https://www.example.com/layouts/system/VisitorIdentification.js
We're loading these two files with the standard Sitecore Razor commands:
@Sitecore.Diagnostics.ClientLog.RenderClientLogConfiguration() and @Html.Sitecore().VisitorIdentification()
So there are a few questions here.
- Does it even make sense to asynchronously load those two java script files or would it break something?
- If it makes sense, how would you do it?
To change the VisitorIdentification.js we could edit \layouts\system\VisitorIdentification.ascx
.
But I'm not sure how to do that with jsnlog.min.js
.
As you can see we already adjusted the path to the file itself, but that's all happening in the configs.
VisitorIdentification.js
is a 3kb file that is requested only on the first page load of a session.jsnlog.min.js
is also relatively small (8kb). Logically, a logging library should be loaded before all other scripts, so deferring its execution is not ideal. Note that if you're not using xDB, you could remove the VisitorIdentification tag altogether since it serves as robot detection for analytics.<head></head>
tags and not be deferred. It wouldn't make much sense then to penalize sites that use this practice.