Inserting instructions for defer/async?

  • Using Google's SearchConsole, I keep seeing indexing errors with almost every PageKit site page when trying to diagnose Google search results and requesting a site to be re-crawled/re-indexed. There might be 24 'resources' on a given page, and Google times out and notes that it can only load 4/7/9 resources out of 24. In this case resources would be everything from favicon, to CSS/JS or images on the page, to font imports.


    After running GTmark and Google's PageSpeed Insights, it shows that I'm getting lousy times in rendering resources that are most of the same ones that Google timed out on, and everything I'm reading says that I need to: "Eliminate render-blocking resources" by using defer or async to alleviate the speed delays - and presumably - the resource errors from the SearchConsole.


    I have always used an existing theme, and heavily modified it to suit whatever site it's set up for, and in the few cases I've needed to add something to a page header in the past, I've used SPQR's Assets extension to insert them. In this case I can't add/insert the assets twice, and I have yet to come across anything in the theme to modify the specific lines to defer or async the basic stuff like jquery and vue, or any of the secondary scripts or CSS. I've found a function to load "(head)", but there's not enough comments in the Avanti theme that I've modified to see what that reference leads to, or from.


    Can anyone point me in the right direction? I'm making the assumption that this needs to be handled in the theme, but is that incorrect?

  • There's no need for anyone to dig for an answer. It turns out that there's an issue with pagekit core that doesn't do what it says on the tin... async or defer do NOT work when there are dependancies, so that pretty much means that there's no way to affect the vast majority of cases where resources are currently called to use any other means to load them other than 'normal'.


    This has been a known issue since 2016. The details are spelled out in several responses in an issue queue, here: https://github.com/pagekit/pagekit/issues/682


    I've added my comments, but I'm doubtful it will be seen as an issue needing a fix anytime soon, but I'll at least mark this thread as 'resolved'.