开发者

Is it possible to prevent/remove any cached script declared by dojo.require?

I'm encountering an issue where most of a page's main logic is offset in a JS file and initialized within a dojo.require call to simplify debugging and development. We're encountering a case where an offload to another page, and then back to the first one and nothing inside our require script loads. I understand this is d开发者_StackOverflowue in part to how dojo.require re-uses cached pages, but I can't go back to the cached version either. Is there a way, besides pasting all the scripts inside the page itself, to force Dojo to reload any require regardless of if it has been cached or not?


Force it to be reloaded in HTML.

    <script type="text/javascript" src="path/to/my/module/name.js"></script>
    <script type="text/javascript">
      ...
      dojo.require("my.module.name");
      ...
    </script>

I don't know if there is any problem on doing it but it does work.


Is there a reason you can't do this the "right" way, by putting the relevant code inside a function and then just calling said function again whenever you want?


If you still think you need to mess with the module loader though I think there are two alternatives after a quick check on the dojo.require source code:

  1. Try to manually clear the module cache

    delete d._loadedModules['my.module.name'];
    
  2. Directly call the internal loader:

    var relpath = d._getModuleSymbols(moduleName).join("/") + '.js';
    d._loadPath(relpath, null);
    

(Try these at your own risk)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜