iPad 网络应用程序。 Javascript,加载所有内容还是切换页面?

发布于 2024-12-06 04:34:37 字数 373 浏览 0 评论 0原文

我们正在开发一个针对 IPAD 的原型 Web 应用程序。我们充分利用了 HTML5,并且该应用程序运行良好。

部分要求是允许应用程序像本机应用程序一样以流畅的方式在“页面”之间切换。

因此,我们的建议之一是改变网络应用程序的工作方式。目前,该应用程序的工作方式与普通网站非常相似,这在切换到具有大图像或动画的页面时会出现问题(因为它们是在页面切换时加载的)。

是否建议更改我们的应用程序,以便主页只需拖动新内容(通过 AJAX)并相应地操作页面,从而创建所谓的单页应用程序。减少 http 请求的数量和大小?

如果是这种情况,并且我们希望通过 AJAX 加载内容,我们如何确定一旦我们将内容拖入,页面上的每个图像都已加载。这将允许我们在转换发生时使用简单的加载图标。

We are working on a protoype web application, targeted at the IPAD. We have made great use of HTML5 and the app is working well.

Part of the requirement is to allow the app to switch between "Pages" in a fluid motion just like a native app.

So one of our suggestions is to change the way the web-app works. At present the app works much like a normal website, this presents problems when switching to pages with large images or animations (As they are loaded when the page switches).

Is it recommended to change our app so what the home page simply drags the new content (via AJAX) and manipulates the page accordingly, thus creating a so called single page app. Reducing the number and size of the http requests?

If this is the case and we wish to load the content via AJAX, how can we be sure that once we have dragged the content in, each of the images on the page have loaded. This will allow us to use a simple loading icon while the transition is taking place.

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

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

发布评论

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

评论(1

走野 2024-12-13 04:34:37

是否建议更改我们的应用程序,以便主页只需拖动新内容(通过 AJAX)并相应地操作页面,从而创建所谓的单页应用程序。减少 http 请求的数量和大小?

在单页应用程序(SPA)中,请求数量可能不会减少,但它们的大小可能会减少,因为您必须加载脚本并仅查看一次,然后只需更新页面的相关部分。 (当然,通过精心构建的缓存控制标头,多页面设计也可以显着提高速度)。 SPA 范例的好处之一是您可以在初始应用程序加载期间加载多个页面,并在必要时显示它们。因此,您可以权衡初始加载中的一些延迟,以换取后续页面更改时更快的用户体验 - 节省您访问服务器的次数,即使它是“AJAX 之旅”。这是我通常喜欢在 SPA 中做出的权衡。

如果是这种情况,并且我们希望通过 AJAX 加载内容,我们如何确定一旦我们将内容拖入,页面上的每个图像都已加载。
如果图像足够小,另一种方法是使用 Base-64 编码图像,这将保证所有内容都可以同时显示。

您可以将内容附加到容器中的 dom,但隐藏它。在所有图像的“加载”事件触发后显示容器。如果您使用 jQuery,可以使用一个插件 https://github.com/alexanderdickson/waitForImages 。如果您使用纯 JS,您可能必须推出自己的解决方案,其中涉及:

  1. 迭代容器中的所有图像,
  2. 存储图像数量 (numImages) 和初始化一个计数器 (numLoaded) 来记录已加载图像的数量,并
  3. 绑定到每个图像的“load”事件,这样当它触发时,numLoaded 计数器就会递增,同时
  4. 检查是否numLoaded == numImages。如果为 true,则所有图像均已加载并且可以显示容器。

Is it recommended to change our app so what the home page simply drags the new content (via AJAX) and manipulates the page accordingly, thus creating a so called single page app. Reducing the number and size of the http requests?

In a single-page app (SPA), the number of requests may not be reduced, but their size may be, b/c you will have to load your scripts and view only once, then just update relevant parts of the page. (Of course, a multi-page design can also have significant speed improvements with carefully-constructed cache-control headers). One benefit of the SPA paradigm is that you can load multiple pages during initial app load, and show them when necessary. Thus, you can trade off some delay in the initial load for a snappier user experience on subsequent page changes - saving yourself a trip to the server, even if it is an "AJAX trip". This is a trade-off that I usually like to make in SPAs.

If this is the case and we wish to load the content via AJAX, how can we be sure that once we have dragged the content in, each of the images on the page have loaded.
If the images are small enough, an alternative is to use base-64 encoded images, this'll guarantee that all content is ready to be displayed at the same time.

You could attach the content to the dom in a container, but hide it. Show the container after all of the images' 'load' events have fired. If you use jQuery, a plugin that helps with this is https://github.com/alexanderdickson/waitForImages. If you are using pure JS, you'd probably have to roll your own solution, which would involve:

  1. iterate over all the images in the container,
  2. storing a count of the number of images (numImages) and initializing a counter (numLoaded) that tallies the number of loaded images, and
  3. binding to each image's 'load' event, such that when it fires, the numLoaded counter is incremented, while
  4. checking whether numLoaded == numImages. If true, all images have loaded and the container can be displayed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文