Jump to content

Defer parsing JS


Adlago

Recommended Posts

Posted

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

Posted

Can you please clarify this, as I'm not sure I understand what you're reporting?

Quote

but loading creates a defer parsing of all JS even when your JS is loaded before closing the body tag.

 

Posted

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.

 

Posted

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

 

 

 

Posted

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.

  • Management
Posted
2 minutes ago, The Old Man said:

Thank you Matt, that's great news! 

Have a donut!

6CF71B04-3208-45C7-8394-BAF81E224EAC.thumb.jpeg.51162e7301a0cf9da85794d3b49d3d50.jpeg

 

Haha, just as I start my diet. Thanks!

 

Posted

I noticed that this change is already in 4.3.3 but i still get this at gtmetrix:

Quote

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

 

Posted
32 minutes ago, RevengeFNF said:

I noticed that this change is already in 4.3.3 but i still get this at gtmetrix:

 

Share your test please

Posted

Tip for all those who still have a defer parsing JS.
After the JS code, before closing the body tag, should not have a html code.

Posted

Thanks @Adlago

In my case it was the plugin Smooth Scroller that was adding html code after the JS.

Quote

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

 

Posted
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

Posted

@Adlago Thanks for the tip.

Quote

Open for editing your theme - Custom Menu.

Find "Javascript include location" and select  "Just before </body> tag".

Here was only to change this option that was perfect. ?

 

Posted
27 minutes ago, Shehi said:

And you guys broke Members filter in Admin CP!!! 

Check templates in your theme - there are probably changes.
Yet the topic here is for a defer parsing java script:cool:

Posted
15 hours ago, Adlago said:

Check templates in your theme - there are probably changes.
Yet the topic here is for a defer parsing java script:cool:

I use default theme for admin cp.

Archived

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

  • Recently Browsing   0 members

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