Jump to content

Defer parsing javascript


Recommended Posts

Hello,

You can use an anonymous function to load the JavaScript, and place it at the bottom of your page. Something like:

(function()

{

	var o = document.createElement('script'); o.type = 'text/javascript'; o.async = true;

	o.src = '/path/to/your/javascript/file.js';

	var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(o, a);

})();



Doing that will defer the loading of that JavaScript until after the page has finished parsing.

That's not always practical though, so you can also use the defer attribute:

http://www.w3schools...cript_defer.asp

Edit: There's a ton of information on Google, notably the following guidelines by Google themselves, inc example(s):

https://developers.g...actices/payload

Hope this helps! :smile:

Link to comment
Share on other sites

How do you edit with defer or async when the line for IPB JavaScript is?:

{parse template="includeJS" group="global" params="$jsModules"}



That one line in globaltemplate is what spits out the list of <script type="text/javascript" src="...

I'm trying now to see if it can be done for the includeJS template.

Link to comment
Share on other sites

Well async gave the same result as moving javascript to footer. Everything worked except for QR and edit boxes. (that I know of)

Edit: Gallery JS does not work also.

Cuts almost 2 seconds! from "first view" page load speed though.

Link to comment
Share on other sites


Hello,



You can use an anonymous function to load the JavaScript, and place it at the bottom of your page. Something like:



(function()

{

	var o = document.createElement('script'); o.type = 'text/javascript'; o.async = true;

	o.src = '/path/to/your/javascript/file.js';

	var a = document.getElementsByTagName('script')[0]; a.parentNode.insertBefore(o, a);

})();



Doing that will defer the loading of that JavaScript until after the page has finished parsing.

That's not always practical though, so you can also use the defer attribute:

http://www.w3schools...cript_defer.asp

Edit: There's a ton of information on Google, notably the following guidelines by Google themselves, inc example(s):

https://developers.g...actices/payload

Hope this helps! :smile:



Not as easy as you think. Implementing this (async) breaks java the same way moving to the footer does. I see you're read topic so I guess you also realize what you posted does not apply easily to IPB;

thanks anyway
Link to comment
Share on other sites


Not as easy as you think. Implementing this (async) breaks java the same way moving to the footer does. I see you're read topic so I guess you also realize what you posted does not apply easily to IPB;



thanks anyway




The OP made no mention of IP.Board, you're making an assumption.
Link to comment
Share on other sites


The OP made no mention of IP.Board, you're making an assumption.




Sorry I thought this forum is about IPB talk and support.. so i didn't thought to mention about it. If you check the link it's fearless-assassins.com and it's running all IPB add-ons.
Link to comment
Share on other sites


Bahaha! Seriously? Maybe he's taking about Wordpress. :thumbsup:




Your sarcasm is very much misplaced.

If you had taken the time to look carefully you'd have noted that this forum is not necessarily IPS-software specific, just look at the other threads - so yeah he could have been talking about Wordpress.

Technically it's in the wrong section anyhow, hehe!

Just so you know in future :smile:
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...