11

当利用 HTML5 功能来指定是否/如何缓存文件时(在 manifest.cache 文件中),是否可以指定整个目录?我可以在 CACHE: 部分下放置我的图像目录的路径并将其应用于该目录中的所有文件,还是我需要明确指定要缓存的图像文件?

换句话说,这可能吗?

CACHE MANIFEST

...

CACHE:
images/

...或者也许是这个?

CACHE MANIFEST

...

CACHE:
images/*

...还是我必须这样做:

CACHE MANIFEST

...

CACHE:
images/logo.png
images/image01.jpg
images/image02.jpg
images/image03.jpg
... (etc)
4

2 回答 2

15

Unfortunately, the third example is the correct one - list every file individually. The html5 doctor article was incorrect at the time the question was posted and has since been amended.
A wildcard * is allowed only in the "online white list" section:

NETWORK:
*

which allows any required files to be downloaded while you are browsing online if not already downloaded (as per normal).
There is also the Fallback section's "page path pattern":

FALLBACK:
/ /offline.html

that kinda works like a wildcard. The initial / will match the path to every page on your site, so any page that is not found in the cache will then use the /offline.html as the replacement fallback. (Note the space between the two slashes.)

于 2012-04-12T18:04:44.330 回答
1

我认为您可以通过在 PHP 文件的帮助下构建 .manifest (或您的示例中的 .cache )文件来实现“通配符”。这样,您可以让 PHP 通过扫描目录并回显每个文件名来处理维护文件名的麻烦。可能最好让 PHP 在你的服务器上放置一个 .manifest 文件,否则离线应用程序可能会认为清单文件已更新并不断刷新缓存。

于 2013-01-16T15:56:39.027 回答