要求js删除定义以强制重新加载 [英] require js remove definition to force reload

查看:109
本文介绍了要求js删除定义以强制重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,我试图从服务器中删除一些amd模块并重新加载更新的版本-目的是不刷新浏览器.

For testing purposes I am trying to remove some amd modules and reload updated versions from the server - with the goal of not refreshing the browser.

我目前正在执行以下操作,但浏览器仍然无法从网络上重新加载项目.

I am currently doing the following but the browser still doesn't reload the items from the network.

var scripts = document.getElementsByTagName('script');
var context = require.s.contexts['_'];
for (var key in context.defined) {
  if(key.indexOf("tests")>-1){
  requirejs.undef(key);
  for (var i = scripts.length - 1; i >= 0; i--) {
  var script = scripts[i];
  var attr = script.getAttribute('data-requiremodule')
    if (attr === key){
    script.parentNode.removeChild(script);
    }
  }}

它从上下文中删除引用,并成功删除脚本标签. 但是a ...

It deletes the references from the context and removes the script tags successfully. But alas...

有人知道从requirejs清除所有引用的机制吗?

Does anyone know the mechanism to clear all the references from requirejs?

非常感谢任何帮助

推荐答案

我们目前正在尝试此实现:

We are currently trying out this implementation:

require.onResourceLoad = function(context, map)
{
    require.undef(map.name);
};

到目前为止,还没有出现任何问题.

No issues has surfaced so far.

IE不太在乎此修复程序. Chrome和FF很好.

IE doesn't care much about this fix. Chrome and FF is fine however.

此外,您应该尝试在PhpStorm中进行实时编辑.奇迹般有效.可以在此处看到演示.虽然只有Chrome.

Also, you should try live-edit in PhpStorm. Works like a charm. A demo can be seen here. Chrome only though.

这篇关于要求js删除定义以强制重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆