Jump to content

Defer parsing JS


Adlago

Recommended Posts

Using Guest Terms is a good idea, but loading creates a defer parsing of all JS even when your JS is loaded before closing the body tag.

I have found a solution and it is very common.
It has to move that

{template="guestTermsBar" if="!\IPS\Member::loggedIn()->member_id and \IPS\Settings::i()->guest_terms_bar" app="core" group="global" params="base64_encode( \IPS\Settings::i()->base_url )"}
		

before

{template="includeJS" if="theme.js_include == 'footer'" app="core" group="global" location="global" params=""}
	

in footer Global Template.

I did too many tests and everything works perfectly - without any defer parsing JS.

Please move it to a next release - everyone will benefit.

Thanks

Link to comment
Share on other sites

The global template footer in the original location of these codes is

-------------------------------------

{template="includeJS" if="theme.js_include == 'footer'" app="core" group="global" location="global" params=""}
{template="guestTermsBar" if="!\IPS\Member::loggedIn()->member_id and \IPS\Settings::i()->guest_terms_bar" app="core" group="global" params="base64_encode( \IPS\Settings::i()->base_url )"}
----------------------------------------	

When loading a site, this causes a defer parsing of all JS. A delay in loading a site is between 8 and 10 points.

In order to have no defer parsing JS, you need to load after. Should be


{template="guestTermsBar" if="!\IPS\Member::loggedIn()->member_id and \IPS\Settings::i()->guest_terms_bar" app="core" group="global" params="base64_encode( \IPS\Settings::i()->base_url )"}
{template="includeJS" if="theme.js_include == 'footer'" app="core" group="global" location="global" params=""}

Loading site in this way does not have a defer parsing JS.

 

Link to comment
Share on other sites

I see what you mean @Adlago

I just did a test before and after. I have JS set before the closing body tag and yet the GTMetrix score for deferring JS was an abysmal F(42).

Quote

732.6KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering.

After moving the line with guestTermsBar up just before includeJS in the globaltemplate, I now get a score of A(98):

Quote

22.2KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering.

Overal Pagespeed score D(68) increased to C(71), loading time 3.1 secs to  2.8 secs.

I used to have a higher score B, sometimes A with IPS 4.2, so I need to see what's changed or broken as I also have less plugins now.

Definitely a far cry from my Wordpress score though!

 

Guestbarterms after includeJS (default):

0C76058C-DC29-41EB-9FD6-164663803EA0.thumb.png.d3a92135a07feaa30f8971d11bccfa05.png

Guestbarterms before includeJS

17293E45-1964-4D75-AEE5-6065FABEB38F.thumb.png.5e6a7a5bf545d3ccd1e06001b99be674.png

Wordpress:

AE23042A-2D2A-47EF-8FB9-06186D004B9D.thumb.png.cfa2d1fbfe56fced98635898d5d49876.png

 

 

 

Link to comment
Share on other sites

Thanks for that @Adlago made the change, nice improvement. Would be great if all these things were done out of the box, but would be good to setup a thread just for page speed improvements.

Code splitting would be another great improvement, to only load the JS which is needed at the time of request.

Link to comment
Share on other sites

7 minutes ago, RevengeFNF said:

 1.0KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering.

this 1K is from your inline JS code Google analysis

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...