plausible/wordpress

Avoid render-blocking JavaScript (checkbot warning)

Closed this issue · 3 comments

oldrup commented

Checkbot throws this warning when proxying the plausible script using the plugin

Avoid render-blocking JavaScript

image

The script loaded in the head section:

image

Their suggestion: "External JavaScript should be included on pages in a way that doesn't block page rendering. A <script src="..."> tag will block HTML rendering until the JavaScript file specified is fetched and the contents of the file has finished executing. Inline JavaScript also blocks rendering until execution is complete. You can stop <script> tags from blocking rendering by placing them directly before the closing tag. Alternatively, for external JavaScript files you can load the script in the background using either 1) <script defer src="...">, which delays script execution until the DOM is ready or 2) <script async src="...">, which will execute the script as soon as it has loaded. Note that defer scripts execute in the order they appear on the page like inline scripts. However, async scripts execute whenever they have downloaded so their execution order can change. This difference is important when scripts have dependencies. "

See also: https://www.checkbot.io/guide/speed/#rule-defer-javascript-loading

Would it work, moving that part to before </body>?

Dan0sz commented

I suggest this should be made an option.

I remember a discussion about being able to move the script to the footer, but this'd be a good alternative.

Adding defer to an analytics script can lead to inaccurate stats, e.g. when the user has a slow connection. So, if your livelihood depends on accurate stats, you might want the script to be render blocking!

Also, I assume you mean </body>?

oldrup commented

Also, I assume you mean ?

Of course, I did 😆Nice catch.

My livehood does not depend on accurate stats, a general idea of what's going on is all I need. But I can see why that is important to some that the script can render block.

Maybe an option?

thanks for the feedback @oldrup! WP plugin should follow what we do elsewhere, which is non-render-blocking by default. we've just made some changes earlier today to fix this and they'll go live with the next release