Load async resource with requirejs timeout

前端 未结 1 1229
盖世英雄少女心
盖世英雄少女心 2021-01-06 05:21

I tried to load the Google APIs Client Library for JavaScript with requirejs and the async plugin:

require.config({
           


        
相关标签:
1条回答
  • 2021-01-06 06:24

    TL;DR; change the !callback to !onload that should fix the timeout.

    define('gapi', ['async!https://apis.google.com/js/client.js!onload'],
        function(){
            console.log('gapi loaded');
            return gapi.client;
        }
    );
    

    The value after the ! is used as the argument name for the async callback, in this case the URI loaded will be something like https://apis.google.com/js/client.js?onload=__async_req_3__ where __async_req_3__ is a global variable (callback function) triggered as soon as the Google API is loaded (notifies the plugin that all dependencies are met).

    0 讨论(0)
提交回复
热议问题