You can just load the necessary s2member javascript/css files on the pages that need it, instead of site-wide.
Here are some pages that discuss the logic behind it:
http://www.s2member.com/forums/topic/remove-css-and-optimize-js/
http://www.s2member.com/forums/topic/javascript-head-includes-move-to-footer/#post-17682
If you only have a few pages that need the s2member code, such as your buy/checkout pages, you could get away with something like the following. Create a file called “s2-hacks.php” (or whatever you want) in your “/wp-content/mu-plugins/” folder, and save the following in it.
<?php
// Remove s2Member JavaScript and CSS files except for the pages below.
if ((strpos($_SERVER['REQUEST_URI'], '/checkout-page-1') === false) && (strpos($_SERVER['REQUEST_URI'], '/checkout-page-2') === false)) {
// Remove CSS files.
function remove_all_s2_css()
{
wp_dequeue_style('ws-plugin--s2member');
}
add_action('ws_plugin__s2member_during_add_css', 'remove_all_s2_css');
// Remove JavaScript files.
function remove_all_s2_js()
{
wp_dequeue_script('ws-plugin--s2member');
}
add_action('ws_plugin__s2member_during_add_js_w_globals', 'remove_all_s2_js');
}
?>
The code above is saying, if a user is viewing “/checkout-page-1” or “/checkout-page-2” then load s2member’s CSS and JavaScript. Otherwise, don’t load it. If you have many checkout pages located in a directory, such as “/checkout/product-1/”, “/checkout-product-2/”, then you can just swap out “/checkout-page-1” with “/checkout” and it’ll protect everything within your directory.
It’s a pretty hacky way to accomplish the goal, but it gets the job done.
By the way, even on pages where s2member is loading, it should be possible to get an excellent pingdom score if you’re covering all other bases: gzipping content, using CDN for static content, setting expiry headers, efficiently loading JavaScript, minifying CSS/JS.
-
This reply was modified 3 years, 4 months ago by
TJ.