Home > Article > Web Front-end > The role of meta in html pages and the analysis of page caching and non-caching settings
This article mainly introduces the caching and non-caching settings of the page and the relevant information about the role of meta in the HTML page. Friends in need can refer to the following
HTML's HTTP protocol header information controls the page's Cache information in several places, including the browser side, the intermediate cache server side (such as Squid, etc.), and the Web server side. This article discusses the caching situation of HTML pages with cache control information in the header information (HTML pages generated by JSP/Servlet) in the intermediate cache server.
The cache header keywords in the HTTP protocol include Cache-Control (HTTP1.1), Pragma (HTTP1.0), last-Modified, Expires, etc.
In HTTP1.0, page caching is controlled through Pragma , which can be set to: Pragma or no-cache. There are many articles on the Internet explaining how to control not allowing browsers or intermediate cache servers to cache pages. The value is usually set to no-cache, but this value is not so safe. Expires is usually set to 0 to achieve the purpose. But if we deliberately need the browser or cache server to cache our page, this value must be set to Pragma.
Enable Cache-Control in HTTP1.1 to control whether the page is cached or not. Here are some commonly used parameters:
•no -cache, neither the browser nor the cache server should cache page information;
•public, both the browser and the cache server can cache page information;
•no-store, request and response No information should be stored in the other party's disk system;
•must-revalidate, for each request from the client, the proxy server must verify with the server whether the cache is out of date;
Last- Modified is only the last generation time of the page, in GMT format;
Expires expiration date value, in GMT format, which means that the browser or cache server must obtain new page information from the real server after this point in time;
The above two values will not take effect if they are set to character GMT format in JSP. They will only take effect if they are set to long type;
The following is a test example:
package com.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ServletA extends HttpServlet { @Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); //servlet页面默认是不缓存的 //本页面允许在浏览器端或缓存服务器中缓存,时限为秒。 //秒之内重新进入该页面的话不会进入该servlet的 java.util.Date date = new java.util.Date(); response.setDateHeader("Last-Modified",date.getTime()); //Last-Modified:页面的最后生成时间 response.setDateHeader("Expires",date.getTime()+); //Expires:过时期限值 response.setHeader("Cache-Control", "public"); //Cache-Control来控制页面的缓存与否,public:浏览器和缓存服务器都可以缓存页面信息; response.setHeader("Pragma", "Pragma"); //Pragma:设置页面是否缓存,为Pragma则缓存,no-cache则不缓存 //不允许浏览器端或缓存服务器缓存当前页面信息。 /*response.setHeader( "Pragma", "no-cache" ); response.setDateHeader("Expires", ); response.addHeader( "Cache-Control", "no-cache" );//浏览器和缓存服务器都不应该缓存页面信息 response.addHeader( "Cache-Control", "no-store" );//请求和响应的信息都不应该被存储在对方的磁盘系统中; response.addHeader( "Cache-Control", "must-revalidate" );*///于客户机的每次请求,代理服务器必须想服务器验证缓存是否过时; System.out.println("进入了servlet"); response.getWriter().write("欢迎光临我的主页"); } }
If necessary To set no caching on the html page, add the following statement to the
tag:<meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="">
Attachment: The role of meta in the html page
Meta is used to simulate the response header message of the HTTP protocol in HTML documents. The meta tag is used in the
and of the web page. The meta tag has many uses. There are two attributes of meta: name and http-equiv. The name attribute is mainly used to describe web pages, corresponding to content (web page content), so that search engine robots can find and classify them (at present, almost all search engines use online robots to automatically find meta values to classify web pages). The most important of these are description (description of the site on search engines) and keywords (categorization keywords), so a meta value should be added to each page. The more commonly used ones are as follows:name attribute
1. is used to describe the generation tool ( Such as Microsoft FrontPage 4.0), etc.;
2. Indicate the keywords of your web page to the search engine;
3.< meta name="DEscription" contect=""> Tell search engines the main content of your site;
4. Tell search engines The author of your site;
5.
The attributes are described as follows:
Set to all: the files will be retrieved, and the links on the page can be queried;
Set to none: the files will not be retrieved , and the links on the page cannot be queried;
Set to index: the file will be retrieved;
Set to follow: the links on the page can be queried;
Set to noindex: the file will not be retrieved, but the links on the page can be queried;
Set to nofollow: the file will not be retrieved, but the links on the page can be queried.
http-equiv attribute
1. and Used to describe the text and language used to create the homepage;
Another example is that English is the ISO-8859-1 character set, as well as BIG5, utf-8, shift-Jis, Euc, and Koi8 -2 and other character sets;
2. Timingly allows the web page to jump within the specified time n Go to the page http://yourlink;
3. can be used to set the web page The expiration time, once expired, must be called again on the server. It should be noted that the GMT time format must be used;
4. is used to set the browser to prevent the browser from accessing the page content from the cache of the local machine. After setting, once you leave the web page, it cannot be retrieved from the cache;
5. cookie setting, if the web page expires, the saved cookie will be deleted. It should be noted that the GMT time format must be used;
6. Web page rating, there is a content setting in IE's internet options that can prevent browsing of some restricted websites, and the website The restriction level is set through the meta attribute;
7. Force the page to be displayed as an independent page in the current window, you can Prevent your own web page from being called as a frame page by others;
8. and Set special effects when entering and leaving the page. This function is the "format/web page transition" in FrontPage ", but the added page cannot be a frame page.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
The difference in usage of href and onclick in the a tag of Html and the priority level
Use Requirejs in Html for modules Analysis of chemical development
The above is the detailed content of The role of meta in html pages and the analysis of page caching and non-caching settings. For more information, please follow other related articles on the PHP Chinese website!