如何让 iOS 缓存带有查询参数的 HTML5 文档?

发布于 2024-12-16 18:04:50 字数 735 浏览 5 评论 0原文

我正在尝试从 iOS 应用程序打开移动 safari,以使用 openURL 打开离线 HTML5 应用程序:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html"]; [[UIApplication共享应用程序] openURL:[NSURL URLWithString:urlString]];

blargh.html 有一个 HTML5 清单:

该清单包含 html 文件: 缓存清单 blargh.html

这一切都按预期工作,当我从 iOS 应用程序打开 URL 时,它会正确缓存并离线工作。但是,如果我包含动态 cgi 参数,它就无法正确缓存:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html?q=p"]; [[UIApplication共享应用程序] openURL:[NSURL URLWithString:urlString]];

这基本上意味着我无法从 iOS 应用程序打开离线 HTML5 应用程序并传递参数并使其正确缓存。我需要在移动 Safari 中打开应用程序,而不是 Web 视图,原因超出了本文的范围。据我所知,没有办法通过 openURL 发送 post 参数。我本来希望 mobile safari 的缓存系统足够聪明,能够忽略 cgi 参数。

有什么建议吗?

I am attempting to open mobile safari from an iOS app to open an offline HTML5 app with openURL:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

blargh.html has an HTML5 manifest:

That manifest contains the html file:
CACHE MANIFEST
blargh.html

This all works as expected, when I open the URL from my iOS app, it is cached properly and works offline. However, it doesn't cache properly if I include dynamic cgi params:

NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/blargh.html?q=p"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

This basically means that I can't open an offline HTML5 app from an iOS app and pass it params and have it cache properly. I need to open the app in mobile safari and not a webview for reasons that are beyond this post. As far as I am aware there is no way to send post params through openURL. I would have hoped that mobile safari's caching system would have been smart enough to ignore cgi params.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离去的眼神 2024-12-23 18:04:50

查询参数会弄乱应用程序缓存,因为它是用于静态内容的。通常的方法是加载静态页面,然后使用 JavaScript 动态填充它,将任何数据缓存在 DOM 存储中 这样您也可以离线使用它。

但是,如果您只需要缓存一个文件并且您的服务器支持路由或URL 重写 ,那么您可以利用包含 appcache 文件链接的页面始终被缓存的事实,因此其本身不必在清单中列出。

将您的 URL 重写为:

http://localhost:8080/blargh.html?q=p

至:

http://localhost:8080/blargh.html/q/p

Query params muck up the app cache because it's intended for static content. The usual approach is to load a static page and then use JavaScript to populate it dynamically, caching any data in DOM Storage so that you can use it offline too.

However, if you just need to cache the one file and your server supports routing or URL re-writing, then you can take advantage of the fact that the page that contains the link to the appcache file is always cached, so doesn't itself have to be listed in the manifest.

Re-write your URL from this:

http://localhost:8080/blargh.html?q=p

To:

http://localhost:8080/blargh.html/q/p
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文