Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

前端 未结 23 1850
太阳男子
太阳男子 2020-11-21 07:19

What would be a good way to attempt to load the hosted jQuery at Google (or other Google hosted libs), but load my copy of jQuery if the Google attempt fails?

I\'m n

23条回答
  •  萌比男神i
    2020-11-21 07:42

    if (typeof jQuery == 'undefined')) { ...
    

    Or

    if(!window.jQuery){
    

    Will not works if cdn version not loaded, because browser will run through this condition and during it still downloading the rest of javascripts which needs jQuery and it returns error. Solution was to load scripts through that condition.

        
      
    

提交回复
热议问题