/    Sign up×
Community /Pin to ProfileBookmark

Falling back to local libraries if cdn fails

I asked whether or not this is even necessary over in the General forum first. So if you wan to comment on that please do it there.

If it is a good idea to add a fallback via javascript, I think I’m most of the way there.

[CODE]if ( !window.jQuery || typeof jQuery == ‘undefined’ ) {

var scripts = document.getElementsByTagName(‘script’);
for(var i=0; i < scripts.length; i++)
{
if(scripts[i].src == translation_array.template_directory_uri + ‘/js/combined-theme-scripts.js’)
{
//scripts[i] is the one

break;
}
}[/CODE]

This checks for jquery and if not present loops through all the script tags until it finds the theme scripts. (I think) I’m new to js.

What I’d like it to do then is build a script tag that points to the local copy of jquery and append it to the dom just before the theme scripts. This all happens in the footer before /body, not in the head. It just needs to add jquery right before the theme scripts to work.

Except I can’t use append I don’t think, because that’s jquery. I need something that does it with javascript only.

Could I get a nudge in the right direction please?

Oh, and if this is a total waste of time and brain power, please go let me know in the General section thread on this. I’d add the link to it but they’re taking their time moderating it, sry.

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Awesome0authorJun 23.2015 — I suppose it would be more like prepend since I want to insert the tag before the existing one? So maybe what I'm asking is what a person has to do in plain javascript to do something like prepend? thanks
×

Success!

Help @Awesome0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...