Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create offline web applications to achieve offline access

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to create offline web applications to achieve offline access related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will have something to gain after reading this article on how to create offline web applications to achieve offline access, let's take a look.

1. Define Manifest

We use manifest to list the resources that need to be accessed offline, which itself is a text type file, the first line is often CACHE MANIFEST, and then lists the resources we need, one per line. There is no fixed naming convention for the file, and there is no requirement for the suffix name. The only requirement is that the suffix name needs to be defined on the server side with the MIME type of text/cache-manifest.

If it is an iis 7 server, follow these steps:

1. For example, if the suffix is .appcache, open the iis7 and select the root node (so that all sites inherit the configuration, or you can configure it for a single site).

two。 Double-click the MIME type on the right

3. Right-click to add the MIME type, which completes the configuration.

When the server is configured, add the manifest file.

The copy code is as follows:

CACHE MANIFEST

ManifestFile.html

Img/1.jpg

Img/2.jpg

Img/3.jpg

Then let's look at the following example.

The copy code is as follows:

Example

Img

{

Border: medium double black

Padding: 5px

Margin: 5px

}

Car1

Car2

Car3

Var buttons = document.getElementsByTagName ('button')

For (var I = 0; I < buttons.length; iTunes +) {

Uploons.onclick = handleButtonPress

}

Function handleButtonPress (e) {

Document.getElementById ('imgtarget') .src =' img/' + e.target.id + '.jpg'

}

The program runs, depending on the browser, some browsers will ask you if you are allowed to save offline data locally, and some will not. Such a simple offline application is created.

two。 Doubt and answer

I also encountered some problems and doubts when learning this part of knowledge, such as:

1. Why do I run vs2010 (my development environment) directly and offline applications don't run correctly?

two。 How do I know if an offline application has been created successfully?

3. How do I know if the current application is offline?

4. I should be offline after suspending the iis service, why do I have to report a 404 error when I refresh the page?

Now I would like to answer these questions I have encountered.

2.1. First, explain the first question. On this question, the key point is how your application web configuration item is configured. If you are using the form of a vs development server, then we have no way to set the MIME type for it, so in this case we cannot use it for offline applications. For the remaining two web configuration methods, as long as you configure the iis server correctly according to the method I introduced above to configure the MIME type, your offline application will run correctly.

2.2. Let's explain the second problem, here with the help of chrome browser debugging tools, use chrome browser to open our web program, press F12, switch to the Resources tab. As long as there is our configuration information under the Application Cache and the cached file can be found, it proves that our offline application has been created successfully.

2.3. Still use chrome debugging tool, or in the Resources tab, notice that the red line is surrounded by the place, Online means online.

Unplug the network cable, display Offline, indicating offline, and then the effect of offline application can be shown.

2.4. As for the last question, we still have to use the debugging tool of the chrome browser. When we paused the iis service, we looked at the display of the Resources tab, which was still Online, but later changed from IDLE to OBSOLETE. This explains why the offline effect of offline applications cannot be displayed when the local iis is paused.

This is the end of the article on "how to create offline web applications for offline access". Thank you for reading! I believe that everyone has a certain understanding of "how to create offline web applications to achieve offline access". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report