Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.js in the footer. How to?
#1
How to move all these blocking javascript to the end of the page?

As soon as we start to use plugins, the <head> get crammed with obese jquery & co scripts that must be put just before the </body> anyway (the page doesn't need 3 versions of jQuery, 2 times the very same .css and a myriad of tiny .js generating a long list of HTTP requests) It spoils the page load speed, the UX and the Gogogl ranking.

How to move them all to the end of the page? (Combining & Minifying them is for another post)

Can't find nor here nor in the Wiki

Any help Idea pointer most welcomed
Reply
#2
You can't , if they are plugins change them to use footer hooks and not header hooks.
I guess you could parse the header output and echo them back to the footer using php dom object or something.

Or rewrite your own get header function and do not call the hook and manage your assets manually
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
I am assuming you are referring to front end assets not backend?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
Thanks for your answer; and your precious time, Really Much appreciated!!

(2014-01-20, 07:32:06)shawn_a Wrote: You can't , if they are plugins change them to use footer hooks and not header hooks.

OK, just discovering http://get-simple.info/wiki/plugins:hook...-end_hooks

(2014-01-20, 07:32:06)shawn_a Wrote: I guess you could parse the header output and echo them back to the footer using php dom object or something.
you means we can rely on the fact a buffer is always used by GS? (i wasn't aware of it).

It's a good idea, as it could be a generic solution for all the plugins.

(2014-01-20, 07:32:06)shawn_a Wrote: Or rewrite your own get header function and do not call the hook and manage your assets manually
oula! it's getting too far for me at the moment! We can override the functions of the GS rendering engine!!??

Well, Great! actually there is a lot under the hood!!! got it now, GS stands for Great & Simple Smile
Reply
#5
You cannot but since templates are only typically 3 functions you can replace them with your own wrappers or native functions.

templates typically only call
get_header
get_content
get_footer

Then there is the menu stuff of course
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
Am I not understanding but cant you write a function in a functions.php file and call the theme_footer function to make your scripts get added there? I am able to do it that way. If this is not what you are asking them please skip over my suggestion Smile
Reply
#7
(2014-01-22, 02:56:38)lnickel Wrote: call the theme_footer function to make your scripts get added there?

Hi

thanks for your help

i'm looking for a too much universal generic can-do-it-all solution Dodgy

idea was to get a function that gather all the .js and all the .css added by the plugins. No theme dependant. A plugin replacing/filtering the get_header and get_footer so existing themes don't have to be modified. Full transparent.

Look today, you have pages including 3 times jQuery, 2 times Bootstrap.css, and different versions of all these, aso...

My customer add a new plugin; that plugin uses jQuery so another reference to jQ is injected in the page header, baaaam, but it's another version, and badaboom, conflict, and boom,
the gallery carousel is not working anymore.

Dring dring, that used-to-be-happy-customer call me, and what i have to tell is that i still haven't finished that magic function cleaning the redundant .js includes and the a-bit-less-happy-customer start to not understand because because Huh

Well. In a perfect world Rolleyes
Reply
#8
Yeah some plugins include their own stuff, but some also offer setting to disable.
Badly written plugins and themes cannot be helped.

If they are using gs asset queuing then you can probably manipulate the queue before the header, then output them yourself.

You can also somehow get plugins to add already loaded exclusions. window.jQuery || document.write etc.

Or replace the whole thing with require.js
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
replace the whole [js.plugins.thing] with require.js > Like me Smile
Reply
#10
I'd love to see your implementation, create a new thread?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#11
(2014-01-22, 10:49:48)shawn_a Wrote: I'd love to see your implementation, create a new thread?

Like your idea, maybe something like a > Plugin Dependencies > would be very useful for community Wink
Reply




Users browsing this thread: 1 Guest(s)