1

I wrote a very fast website that scored 99% on GTMetrix and PageSpeed Insights.

Then I added Google Analytics and Google Adsense to the site, adding the scripts to the head section, as advised by Google.

Subsequently PageSpeed Insights has reduced my score to 61, blaming slow and unused javascript.

It is saying things like "Third-party code blocked the main thread for 1,080 ms". (Why is it even blocking? It is marked as async..)

It's really absurd, and my website ranking has also tanked.

Can I fix this by putting the relevant code at the bottom instead of the top?

1 Answer 1

2

I think there are two options you have, the first would be trying to add the defer attribute to each script. It might work in conjunction with async to make sure the core info of your site (html and css) is loaded first.

I believe (don't quote me on this though) that defer essentially reproduces what you proposed in putting the code in the footer - waiting to load after more essential things do.

More info can be found on [web.dev][1] which you may have seen linked on Pagespeed insights.

The other option would be to create a Google Tag Manager account and drop those scripts in there. Then, you embed the GTM script, which has consolidated your two scripts, and the server only needs to make one request.

I hope that helps! It's always frustrating when Google tools like PSI says other Google scripts are harming your site.

2
  • 1
    Hello, I did this, it made no difference unfortunately. Commented Dec 18, 2020 at 17:27
  • Sorry about that - what happens when you put the code before the closing body tag like you mentioned in your post?
    – James
    Commented Dec 18, 2020 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.