如何向清单文件 HTML5 添加参数以实现离线模式?

发布于 2024-09-29 16:55:11 字数 432 浏览 6 评论 0原文

我有一个网络应用程序,我想让它也离线运行。在此应用程序中,我只有一个表单,并使用 PHP 来提交它。我正在使用像 http://building- 中描述的 manifest.php 文件iphone-apps.labs.oreilly.com/ch06.html

问题是我需要以某种方式在清单中添加表单中的参数,以缓存正确的文件,例如文件welcome.php?name=aaaa 而不是welcome.php 。因此,我需要在 manifest.php 中使用 GET 来获取名称。但如果我理解得很好,清单文件是在提交表单之前创建的,因此“名称”上的值为空。

有没有办法在我的清单文件中添加这些参数以便离线运行应用程序?

谢谢

I have a web application and I want to make it run offline as well. In this application I just have a form and I am using PHP for submitting it. I am using a manifest.php file like the one described in http://building-iphone-apps.labs.oreilly.com/ch06.html .

The problem is that I need somehow to add the parameters from the form in the manifest, for caching the right file, for example the file welcome.php?name=aaaa and not the welcome.php . So I need to use a GET for the name in the manifest.php. But if I understood well the manifest file is created in the beginning before the form is submitted so the value on "name" is empty.

Is there a way to add these parameters in my manifest file for running the application offline as well?

Thanks

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

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

发布评论

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

评论(2

蓦然回首 2024-10-06 16:55:11

您可以做到这一点的唯一方法是在清单中列出文件及其参数,因此您必须提前知道所有可能的参数,然后使用您的manifest.php将它们吐出,最终得到一个清单文件看起来像这样:

CACHE MANIFEST
welcome.php?name=aaaa
welcome.php?name=aaab
welcome.php?name=aaac
...thousands more lines...
welcome.php?name=zzzz

NETWORK:
welcome.php

但是,如果(看起来)您想向用户呈现个性化的欢迎页面,我强烈建议您不要这样做。通过这种方法,每个用户都将下载每个欢迎页面,即使他们只需要查看其中一个页面。

我认为有两种方法会更好:

1:提供个性化页面

如果唯一改变的是这个页面,则强制用户在访问welcome.php页面之前登录,然后使用会话变量传递个性化页面的查询参数。然后,您只需在清单中指定welcome.php,每个用户就会缓存一个个性化版本。

2:编写完整的离线应用程序

如果您的网络应用程序在每一步都需要包含用户特定数据,您需要分解哪些是常见的应用程序组件以及哪些是用户数据,并分别为它们提供服务。如果您的应用程序要离线执行任何操作,则将使用 JavaScript 执行此操作,因此您应该使用 JavaScript 更新浏览器中的页面,而不是使用 PHP 在服务器端生成整个页面。

大多数 PHP 页面基本上都是模板,您将通过 JavaScript 加载用户数据(对于浏览器中没有离线功能的用户,您仍然可以使用“旧”方式填充它们)。您将至少有一个 PHP 页面,用于响应 AJAX 请求来传递数据。对于这种方法,您需要了解本地存储以及各种 JavaScript API管理缓存并检测离线状态。一旦用户决定安装 Web 应用程序的离线版本,您就会下载该用户的所有数据并将其放入本地存储中,然后使用该数据在 用户离线。当用户重新上线时,所做的任何更改都需要同步回服务器。

The only way you can do that is to list the files with their parameters in the manifest, so you would have to know all the possible parameters in advance and then use your manifest.php to spit them out, ending up with a manifest file that looks something like this:

CACHE MANIFEST
welcome.php?name=aaaa
welcome.php?name=aaab
welcome.php?name=aaac
...thousands more lines...
welcome.php?name=zzzz

NETWORK:
welcome.php

However, I strongly recommend you don't do it this way if (as it looks like) you want to present a personalised welcome page to the user. With this approach every user will download every welcome page, even though they only need to see one of them.

There are two approaches I think will work better:

1: Deliver personalised pages

If only thing which changes is this page, force the user to logon before accessing the welcome.php page, then use a session variable instead of a query parameter to deliver the personalised page. You then just need to specify welcome.php in your manifest and every user will cache one personalised version.

2: Write a full offline app

If your web app is going to have user specific data at every step you need to break down what are the common application components and what is the user data, and serve them separately. If your app is going to do anything offline it's going to be doing it with JavaScript, you should therefore use JavaScript to update the page in the browser rather than generating entire pages on the server side with PHP.

Most of your PHP pages are basically going to be templates which you will load with user data through JavaScript (you can still populate them the 'old' way for users who don't have offline capability in the browser). You will have at least one PHP page which delivers data in response to AJAX requests. For this approach you're going to need to learn about Local Storage and the various JavaScript APIs for managing the cache and detecting offline state. Once the user decides to install the offline version of your web app you download all of that user's data and put it in Local Storage, then use that data to update each page as it loads when the user is offline. Any changes made then need to be synced back to the server when the user is back online.

舂唻埖巳落 2024-10-06 16:55:11

由于应用程序缓存是在它引用的页面之后加载的。当参数可用时,您必须通过 applicatonCache.update() 重新加载缓存。

将参数注入清单的技巧是在调用 update() 之前设置 cookie。您的服务器端脚本获取 cookie 并可以生成适当的清单内容。

Due to applciation cache is loaded after the page it references to. You have to reload the cache by applicatonCache.update() when the parameters are available.

The trick to inject the parameters into the the manifest is to set cookies before invoking update(). Your serverside script gets the cookies and can generate the appropriate manifest content.

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