javascript - 如何防止@require 缓存外部js 脚本

标签 javascript firefox greasemonkey scriptish

我目前正在尝试弄清楚如何在我的网络服务器上的 scriptish/greasemonkey 脚本中包含一个 javascript,并让它在每次调用用户脚本时重新加载脚本。

我正在我的网络服务器上编辑脚本,我真的不想每次对包含的脚本进行更改时都重新安装用户脚本。

有什么办法可以解决这个问题吗?我一直在寻找答案,但到目前为止没有找到答案。

明确地说,我的用户脚本如下所示:

// ==UserScript==
// @id             HET
// @name           SettingsHandler
// @version        1.0
// @namespace      HET
// @require        http://urltoscript/scripts/he/lib.js
// @run-at         document-end
// ==/UserScript==

我的外部脚本如下所示:

alert('got it');

所有这些对于测试目的来说仍然非常容易。此设置有效,但只有第一次,当我更改我的 lib.js 脚本时,用户脚本仍会读取旧脚本。有没有办法阻止用户脚本缓存外部脚本?或者是否有任何其他元标记可以帮助我?

提前致谢, 戴夫

最佳答案

这是唯一可行的答案 https://github.com/Tampermonkey/tampermonkey/issues/475

推荐选项 4。但是它们是异步加载的,因此加载顺序可能不同

There are several ways to ease your pain. :)

  1. You can increase the version number before saving the script and all external resources will be reloaded.
  2. After setting "Config mode" to "Advanced" you can configure the external update interval. Note: "Always" still means after the resource was used. So you might need to execute/load the page twice.
  3. If you use Tampermonkey Beta (Chrome or Firefox) you can edit the external resource in place (because there now is a edit button besides the delete button).
  4. Copy the resources and store them locally. After you've enabled "Local file access" at Chrome's extension management page or Tampermonkey's settings page (if you're using Firefox) you can @require them via a local file:// URI.

关于javascript - 如何防止@require 缓存外部js 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30109626/

相关文章:

css - 背景图像路径在 Firefox 中不起作用

jquery - 访问目标页面上 jQuery 的现有副本

javascript - 如何为Greasemonkey授予Window.opener.location.href权限?

javascript - Greasemonkey 更改表单中单选按钮的值?

javascript - Firefox 中奇怪的 JavaScript 滚动

javascript - 在 Firefox 的 iframe 中聚焦

javascript - Angular 4 - 如何从指令中运行动画?

javascript - Facebook 如何防止触发点赞按钮的自动点击?

javascript - play() 请求被 pause() 调用中断

javascript - WebCryptoAPI 是否在浏览器或远程服务器上运行