net :: ERR_FAILED用于manifest.cache中的网络项

时间:2016-09-27 18:28:57

标签: javascript jquery html cache-manifest manifest.cache

我的缓存清单文件如下所示:

CACHE MANIFEST

calendar.html
scripts/jquery.js
scripts/calendar.js

NETWORK:

https://apis.google.com/js/client.js

我的calendar.html看起来像:

<html manifest="calendar.cache">
  <head>
    <script src="scripts/jquery.js" type="text/javascript"></script>
    <script src="scripts/calendar.js" type="text/javascript"></script>
    <script src='https://apis.google.com/js/client.js?onload=checkAuth'></script>
  </head>
  <body>
    <div id="authorize-div" style="display: inline">
      <span>Authorize access to Google Calendar API</span>
      <!--Button for the user to click to initiate auth sequence -->
      <button id="authorize-button">
        Authorize
      </button>
    </div>
    <pre id="output"></pre>
    <script>

    $(document).ready(function(){

        console.log("ready");
    })
    </script>
  </body>
</html>

如果我禁用缓存,一切正常。但是,当启用缓存时,我会收到apis.google.com/js/client.js文件的错误。错误是jquery.js:5 GET https://apis.google.com/js/client.js?onload=checkAuth&_=1474962265124 net::ERR_FAILED。这是谷歌Chrome浏览器,但我得到类似的错误的Firefox。我错过了什么?

1 个答案:

答案 0 :(得分:2)

这是由于您为client.js传递的那些参数引起的,即{。{1}}

在web中,只要您传递任何参数,请求被认为是唯一的。因此,就浏览器而言,清单中声明的​​脚本不一样

?onload=checkAuth

但在https://apis.google.com/js/client.js // script A https://apis.google.com/js/client.js?onload=checkAuth //script B ≠ script A 中,您已将脚本A声明为非缓存。现在您可以猜测将清单更改为以下将解决问题

calendar.cache

Ofc只是删除CACHE MANIFEST calendar.html scripts/jquery.js scripts/calendar.js NETWORK: https://apis.google.com/js/client.js?onload=checkAuth 也可以在不需要回调的情况下工作。只需擦除整个缓存并重新加载以查看魔法!