3

我正在使用带有 mustache.js 的 Backbone.js,并且正在使用 ajax 加载我的模板。我的问题是模板是从缓存中加载的(如果重要的话,使用 ctrl+F5 刷新!)。现在我对模板进行了更改,但它仍在加载旧版本。它在隐身模式下工作得很好。有没有办法防止这种情况?也许阻止 Mustache 缓存模板?

呈现模板的代码是:

$.get(this.templatesPath + this.template, function(resTemplate){
        var html = Mustache.render(resTemplate, that.personData);
        that.$el.html(html);
    });

我的第一个想法是使用其他函数而不是“Mustache.render()”,比如“Mustache.to_html()”。但是查看源代码会发现 to_html() 只是调用了 render()。

有什么想法吗?

4

1 回答 1

0

很抱歉挖掘了这个非常古老的问题,但我正在寻找类似问题的答案,但最终没有在任何地方找到它。这个问题是搜索“mustache disable caching”时出现的第一个问题。

我将 Mustache 和 Express 与 mustache-express 模块一起使用。我能够通过以下方式禁用缓存:

const Mustache = require('mustache-express')();
delete Mustache.cache;

我希望这对将来的其他人有所帮助。

于 2021-12-19T03:57:39.670 回答