Defer cornerstone javascript code

I did open a topic on this a while ago but looks like I cant reply to it for some reason. I noticed cornerstone js (one of them) is 124kb. I would like to defer it. I found this script while searching online and I would like to know if it will defer it.

/* Defer Parsing of Javascript*/
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
if ( strpos( $url, ‘jquery.js’ ) ) return $url;
return “$url’ defer “;
}
add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );

I would rather just defer cornerstone, the cs-body.js. A better option would be to get it to load from the footer and not from the header. I am using a plugin to get everything from the footer but all of cornerstone js files are still loading in the header.

1 Like

Hi @Bark201,

Thanks for writing in.

Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself.

I can only suggest on how to add Script in your footer.

You can edit your Child Theme’s function.php file and do one of the following to add the JS in the footer.

For example,

add_action('wp_footer','custom_footer_script');
function custom_footer_script() { ?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<?php	
}

If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

Thank you for your understanding.

Thank you for the reply. The above script wont help. Im using revslider at the top of the page, if I move jquery to footer it wont load. My problem is with cornerstone JS. It doesnt move to the footer.

I disagree this is the customization of it. I didnt choose cornerstone js to load in the header so I will appreciate getting that script out of the header. Its the cs-body.js that comes from cornerstone. Im not sure why the cs.-body.js is even loading above the fold. I am using a plugin to move js scripts to the footer besides jquery and all of cornerstone js files refuse to move.

Moving scripts is part of optimization and optimization is outside the scope of our support. There is no option to move scripts in X nor Cornerstone so you’ll need a plugin or script to do that so that is not part of our support.

Also, if you understand how Javascript works, not all scripts could be simply placed in the footer. That is because some functions needs to be in the header or elsewhere where it needs to be loaded first.

You’ll need to hire a web developer for this. We do have an in-house custom development team that offer paid services, who may be able to assist. They can be contacted at pinnacle@theme.co if this is of interest to you.

Thank you for your understanding.

I know that not all js can be in the footer but then there should be an option to defer the scripts, right? I can find a plugin that will force it to defer but I would rather have that option available in cornerstone just like I have that option in revslider for example. With revslider I have a choice whether to defer to load from footer. Defer is a better option for me.

1 Like

Regretfully, this is not an option offered in Cornerstone so you need a third party plugin to do it. Please take note though that issues arising from optimization would be outside the scope of our support.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.