How to use a custom zp_apply_filter('theme_head')

Ok I am optimizing my website..
I would like to replace the jquery script loaded from the zp-core folder with the one from the CDN to reduce load time
http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js
Since a lot of sites use this URL the script will probably be already cached.

How can I change `zp_apply_filter('theme_head')`?

I guess I have to use a custom `my_printZenJavascripts()` in my templates functions.php and than register the filter with `zp_register_filter('theme_head','my_printZenJavascripts',0);`

Question is.. where should I do this.

Also would like to know if this is a good idea after all. I guess ZP guarantees compability with the install and the current version, so updating ZP and it might not work with the Jquery version if I forget to update?

Comments

  • acrylian Administrator, Developer
    First, the jQuery we ship is the one that we test all jQuery dependent official plugins with (we use it on the backend as well). So if you choose to load always the latest some things might not work. We once upgrade to fast which especially on the backend broke a lot of things as the plugins used had not been updated. Once we even had to search for a new solution at all. But that was primarily backend. While required on the backend it is not directly on a theme besides some plugins.

    Actually there is no way to disable loading of jQuery on the theme unless you remove the theme_head filter. If you do you might also loose other functionality as all extra scripts and other stuff are loaded via that (the backend is of course not affected). But otherwise you would load jQuery double.
    For the usage of the filter look at official plugins like the html_meta_tags one for example.

    I doubt that that single jquery file really causes load times issues as it is cached by the browser anyway. I know placing stuff on several hosts is a recommendation for site speed up but actually it is alway external servers like ads, embedded vides and such that seem to slow down sites.
  • Yeah I thought so, I leave it up to ZP.
    I know the JS is cached. It's just the first visit that the 100Kb has to load..
    Thanks for the explanation acrylian.
  • acrylian Administrator, Developer
    Those 100kb will have to be loaded no matter from where...;-)

    The reason it is recommend to put parts of a site on high traffic sites is that browser have a limit of http request per domain/server (as you probably know) you can exceed that way.

    I however have sent sbilliard a mail to discuss an option to not load the base jQuery stuff optionally (so theme authors can choose if they really need to). So maybe we add that some time.
  • You should look at http://www.zenphoto.org/news/headConsolidator. You could modify it to substitute your jQuery load for Zenphoto's. Of cousre all the caviats that acrylian mentioned still apply.
  • Sweet! I'll check it out, thanks sbillard!
Sign In or Register to comment.