Use the Link tag to load resources until the resources are loaded.

Source: Internet
Author: User

In the previous article, we talked about how to force the client to refresh. js files directly. This article utilizes several features of the cache mechanism.

This article uses a common tag to load resources that you think need to be loaded.

Original Intention

We all know that the link tag is used to load css files. I wonder how many kids shoes mistakenly think that they can only load css files? How many children's shoes have forgotten it? Why do we need to write link in a single article? It is just to remind ourselves that we should never forget the way the browser treats things.

Assume that you are a browser developer and you need to load css files when creating link labels. This is your original intention, but before loading your page, you don't actually know whether the css file you are loading is a real css file. It may not exist. It may be a few things, or it may be css as you wish, however, all these judgments will be known at the end.

We often encounter the need to load some data before the current page Jump, which may be for cache or other reasons, such as getting Http Headers.

For example, we know that when we clear Cookies, we need to send the set-cookies http header from the current domain. At this time, when we encounter the need to clear multiple domain Cookies at the same time (cross-domain also need to set Http Headers P3P, understanding P3P can refer to the interpretation of the http://www.cnblogs.com/volnet/archive/2012/11/25/2787197.html article .), We need to request the http headers for clearing Cookies in multiple domains at the same time on one page. We usually have a page to send these requests. Suppose this is a cross-origin exit operation, that is, to obtain the http headers for clearing Cookies from multiple domains, we usually jump to a page (such as the logon page) after exiting. How can we ensure that before the jump, have these pages been called?

The link label can be used here. Maybe you will ask why not multiple ajax requests? In the face of cross-origin problems, ajax is usually limited and requires special settings in the browser, while the link tag does not have such concerns. By default, it supports cross-origin.

The link tag loading is blocked. That is to say, the page will not continue to jump until the link tag is loaded. (Of course, this may sometimes become another problem. For example, if the called Page never stops returning, the page will always become stuck, this can be used to remove the link through the setTimeout script before loading the link ).

Conclusion

Link ensures that the loaded resources are loaded before the page Jump.

The following example proves the conclusion:

1. Block. aspx. cs: A resource used to simulate ultra-long loading time

2. MetaRefreshWithBlock. aspx: A jump page used to load Blocks

3. Content. aspx: A target page

Block. aspx. cs

    public partial class Block : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {            Response.Clear();            int seconds = 0;            while (seconds < 10)            {                Response.Write(string.Format("Seconds = {0}<br />", seconds));                Response.Flush();                System.Threading.Thread.Sleep(1000);                ++seconds;            }            Response.End();        }    }

MetaRefreshWithBlock. aspx

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "MetaRefreshWithBlock. aspx. cs" Inherits = "WebSiteLinkTagBlock. MetaRefreshWithBlock" %> <! DOCTYPE html> 

Source code download: http://files.cnblogs.com/volnet/WebSiteLinkTagBlock.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.