简体   繁体   English

我可以在首次运行时使我的Web应用完全离线吗?

[英]Can I make my webapp completely offline during first run?

I am having web application which when loaded makes some XMLHttprequests to get some dynamic data. 我正在使用Web应用程序,该应用程序在加载时会产生一些XMLHttprequests以获取一些动态数据。

Problem is that this webapp takes lot of time during first run, since it loads lot of resources online. 问题在于,此Web应用程序在首次运行时会花费大量时间,因为它会在线加载大量资源。

I want to make this first run fast by putting resources in application and using HTML5 appcache. 我想通过将资源放入应用程序中并使用HTML5 appcache来使其快速运行。 After my changes it works now as most of resources can be loaded from HTML5 cache. 更改后,它现在可以正常工作,因为可以从HTML5缓存中加载大多数资源。 I have added cache manifest to my app. 我已将缓存清单添加到我的应用中。

This is good but my app also makes few XMLHttpRequest. 这很好,但我的应用程序也很少生成XMLHttpRequest。 I know this data is dynamic but during first run I want to load this data from static resources. 我知道此数据是动态的,但在首次运行时,我想从静态资源中加载此数据。 Is it possible that I can store this data in JSON format in JS or HTML files and when XMLHttpRequests are made it should pick from those static resources. 我是否可以将这些数据以JSON格式存储在JS或HTML文件中,并且在做出XMLHttpRequests时应该从那些静态资源中进行选择。

I researched a lot on internet but looks like its not possible, not able to came across a single example with the help of which I can be sure that this is possible. 我在互联网上进行了很多研究,但似乎无法实现,在我的帮助下,我无法碰到单个示例,因此我确信这是可能的。

Any suggestions guys? 有什么建议吗?

I'd suggest you either 我建议你要么

  1. Bootstrap the JSON data right in the HTML file's source code if it's generated dynamically 如果是动态生成的,则在HTML文件的源代码中引导JSON数据
  2. Store the responses in localStorage and if the requests fail, fallback to that 将响应存储在localStorage中,如果请求失败,则回退到该位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM