更改offline.js中允许的服务器响应时间

Change time allowed for server response in offline.js

本文关键字:服务器 响应时间 offline js 更改      更新时间:2023-09-26

我在一个移动web项目中使用offline.js。在我运行的特定环境中,该脚本在报告与服务器的连接丢失时似乎有点过于热心。如何修改它以使服务器有更长的响应时间?

尝试用所需的xhr设置Offline.options中的检查:

Offline.options = {
    checks : {
        xhr : {
            url : function () {
                return "/favicon.ico?_=" + ((new Date()).getTime());
            },
            timeout : 10000, // change this to the timeout you need
            type : 'HEAD'
        }
    }
};

检查源代码第28行中的默认值。您可以在文档中的Checking头中看到设置检查的方法。

考虑一下:

选项(任何选项都可以作为函数提供),默认值:

{
  // Should we check the connection status immediatly on page load.
  checkOnLoad: false,
  // Should we monitor AJAX requests to help decide if we have a connection.
  interceptRequests: true,
  // Should we automatically retest periodically when the connection is down (set to false to disable).
  reconnect: {
    // **How many seconds should we wait before rechecking**.
    initialDelay: 3,
    // **How long should we wait between retries**.
    delay: (1.5 * last delay, capped at 1 hour)
  },
  // Should we store and attempt to remake requests which fail while the connection is down.
  requests: true,
  // Should we show a snake game while the connection is down to keep the user entertained?
  // It's not included in the normal build, you should bring in js/snake.js in addition to
  // offline.min.js.
  game: false
}