This topic contains 1 reply, has 2 voices. Last updated by Philly 4 years, 3 months ago.
Topic Author | Topic |
---|---|
Posted: Monday Sep 10th, 2012 at 11:19 pm #24830 | |
This isn’t a question–I’m posting a possible solution for those who are in need of what this topic is about. A while ago I came across this post ( http://www.s2member.com/forums/topic/javascript-head-includes-move-to-footer/ )that asked how to put the s2member javascript at the bottom of the document instead of the head section, which is a recommended optimization. There were suggestions for how to remove all javascript or how to do it on per-page basis, but there wasn’t a clear, final suggestion about how to do this easily and quickly. After doing some research I came across two sites that appear to accomplish the task of putting all s2member javascript at the footer of the document, while 1) maintaining the jQuery “dependency” and 2) not breaking other scripts. The first part is to move all the queued javascript from the head to the footer. This site explains how to do it: The step above accomplishes the bulk of the solution by moving all javascript to the footer in one fell swoop. But one problem I had with it is that s2member (actually core WordPress) is using jQuery version 1.7.2, and it’s loading the file locally instead of Google CDN. I know I can use the WordPress plugin “Use Google Libraries” to accomplish this for me, but I prefer to load a jQuery version higher than 1.7.2. I also want to have a local fallback, just in case google’s CDN becomes inaccessible. I know that their CDN’s are unlikely to go down, but in some countries Google’s CDN is blocked, and I still prefer a fallback. So, just moving the javascript to the footer isn’t enough. I did come across a method to “deregister” jQuery, then “register” it again using the CDN address, but this has the side effect of breaking some scripts that list jQuery as a WordPress “dependency”. That’s when I came across this site which has a clever way of loading a preferred version of jQuery from Google’s CDN, and having a local fallback, while not breaking any WordPress queued scripts that list jQuery as a “dependency”: If there’s a flaw in this approach, it would be great to have s2member support chime in. I especially like this method because all the necessary code can be placed in a theme’s functions.php file, thereby leaving s2member’s core files untouched. Hopefully this can be of use to others that would like to optimize s2member by having all its javascript code at the footer/bottom of the page instead of in the head. Maybe something like this could also be incorporated into some future version of s2member?
|