latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Solution: s2member javascript head to footer

Home Forums Community Forum Solution: s2member javascript head to footer

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
Username: wellwater

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 ( )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?

  • This topic was modified 4 years, 3 months ago by  Eduan. Reason: Moved to the customer support forums

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Wednesday Sep 12th, 2012 at 6:15 am #24979

I’m not sure I would agree with the approach outlined here, s2members js file contains important variables that you may want loaded before the page starts to render in the same way you would always put a script like modernzer in the head.

There is definitely much improvement to be had here though and I know they’re working to improve this, I personally hope that the new s2member will serve any js minified and gziped.

Viewing 1 replies (of 1 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.