您好,我想知道当我在新主题组件的 Head 部分添加的此脚本中更改用户浏览器会话中的缓存 JavaScript 的图片 URL 和/或 \u003chref\u003e 链接时,有什么方法可以更新它们:
使用此当前的小部件代码,用户需要刷新浏览器才能看到新更新的图片或更改的链接。我曾认为这会通过某种 AJAX 方法在浏览器缓存中更新,就像 CSS 更改会立即反映出来而无需重新加载页面一样,但自定义 Head 脚本并非如此。
我注意到 House Ads 插件通过某种方式在更改广告的 HTML 后立即强制刷新。对于 House Ads 插件,我在 house-ads.js 中搜索关键字 refresh 时发现了以下内容:
@observes("refreshOnChange")
refreshAd() {
if (this.get("listLoading")) {
return;
}
this.set("adHtml", this.chooseAdHtml());
},
didInsertElement() {
this._super(...arguments);
if (!this.get("showAd")) {
return;
}
if (this.get("listLoading")) {
return;
}
if (adIndex.topic_list_top === null) {
// start at a random spot in the ad inventory
Object.keys(adIndex).forEach((placement) => {
const adNames = this.adsNamesForSlot(placement);
adIndex[placement] = Math.floor(Math.random() * adNames.length);
});
}
this.refreshAd();
},
类似的方法是否可以应用于我的自定义插件 JavaScript?