Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Jquery CDN with fallbacks


Go to End


1564 Views

Avatar
soulrolll

Community Member, 9 Posts

7 October 2014 at 2:36pm

Edited: 07/10/2014 2:37pm

So far I have only been able to get the cdn working on both the cms and pages

public function init() {

parent::init();

// Stop Silverstripe from loading it's own version of jQuery.
Requirements::block(SAPPHIRE_DIR .'/thirdparty/jquery/jquery.js');

// Require the CDN version
Requirements::javascript("//cdn.jsdelivr.net/jquery/1.7.2/jquery.min.js");

}

I was wondering if anyone could shed some light on a tidy fallback code for this,

http://www.meerware.com/thoughts/2013/06/cdn-javascript-with-silverstripe/

The comment by Bauke doesn't seem to be working and I am a bit stumped on using Requirements::customScript to achieve what I want. Basically just want something there in the unlikely event that the cdn fails.

Any help would be much appreciated :)