如何附加最新的html文件,而不是缓存

时间:2022-08-15 13:55:23

I am doing a webpage for my band right now, and I have a problem with appending html files.

我正在为我的乐队做一个网页,我有一个附加html文件的问题。

I have an index file with basic content which is more like a template. For example the news are stored in a seperate html file and I used jQuery's .append do "bind" them into the space where I want it to be.

我有一个基本内容的索引文件,更像是一个模板。例如,新闻存储在一个单独的html文件中,我使用jQuery的.append将它们“绑定”到我想要的空间。

The news.html changes quite often, and the problem is: The user does not see any changes, because it's still stored in the cache. I tried things like

news.html经常更改,问题是:用户没有看到任何更改,因为它仍然存储在缓存中。我尝试过类似的东西

<meta http-equiv="expires" content="0">

and

<meta http-equiv="Cache-Control" content="no-cache" />

for both, the index and the news HTML, but it did not work. I assume it's because of the .append. Is there a way, to tell the append function, that it should always load the .html from server?

索引和新闻HTML,但它没有用。我认为这是因为.append。有没有办法,告诉append函数,它应该始终从服务器加载.html?

Greetings capekall

1 个解决方案

#1


1  

How are you loading the news.html? With $.ajax? Then you can pass a parameter to specify that it should not be added to the cache (see the cache-property in the settings):

你是如何加载news.html的?使用$ .ajax?然后,您可以传递一个参数以指定不应将其添加到缓存中(请参阅设置中的cache-property):

http://api.jquery.com/jquery.ajax/

The default value is true, which means the page IS added to the cache.

默认值为true,表示页面IS已添加到缓存中。

You need to do something like:

你需要做一些事情:

$.ajax("/news.html", {cache: false});

#1


1  

How are you loading the news.html? With $.ajax? Then you can pass a parameter to specify that it should not be added to the cache (see the cache-property in the settings):

你是如何加载news.html的?使用$ .ajax?然后,您可以传递一个参数以指定不应将其添加到缓存中(请参阅设置中的cache-property):

http://api.jquery.com/jquery.ajax/

The default value is true, which means the page IS added to the cache.

默认值为true,表示页面IS已添加到缓存中。

You need to do something like:

你需要做一些事情:

$.ajax("/news.html", {cache: false});