last-modified

浏览器缓存知识小结及应用

谁说胖子不能爱 提交于 2020-01-30 16:37:04
浏览器缓存,也就是客户端缓存,既是网页性能优化里面静态资源相关优化的一大利器,也是无数web开发人员在工作过程不可避免的一大问题,所以在产品开发的时候我们总是想办法避免缓存产生,而在产品发布之时又在想策略管理缓存提升网页的访问速度。了解浏览器的缓存命中原理,是开发web应用的基础,本文着眼于此,学习浏览器缓存的相关知识,总结缓存避免和缓存管理的方法,结合具体的场景说明缓存的相关问题。希望能对有需要的人有所帮助。 1 浏览器缓存基本认识 它分为强缓存和协商缓存: 1.1 浏览器在加载资源时,先根据这个资源的一些http header判断它是否命中强缓存,强缓存如果命中,浏览器直接从自己的缓存中读取资源,不会发请求到服务器。比如某个css文件,如果浏览器在加载它所在的网页时,这个css文件的缓存配置命中了强缓存,浏览器就直接从缓存中加载这个css,连请求都不会发送到网页所在服务器; 1.2 当强缓存没有命中的时候,浏览器一定会发送一个请求到服务器,通过服务器端依据资源的另外一些http header验证这个资源是否命中协商缓存,如果协商缓存命中,服务器会将这个请求返回,但是不会返回这个资源的数据,而是告诉客户端可以直接从缓存中加载这个资源,于是浏览器就又会从自己的缓存中去加载这个资源; 1.3 强缓存与协商缓存的共同点是:如果命中,都是从客户端缓存中加载资源,而不是从服务器加载资源数据

ETag

我与影子孤独终老i 提交于 2020-01-30 16:33:36
HTTP协议规格说明定义ETag为“被请求变量的实体值”。 另一种说法是,ETag是一个可以与Web资源关联的记号(token)。典型的Web资源可以一个Web页,但也可能是JSON或XML文档。服务器单独负责判断记号是什么及其含义,并在HTTP响应头中将其传送到客户端,以下是服务器端返回的格式: ETag:"50b1c1d4f775c61:df3" 客户端的查询更新格式是这样的: If-None-Match : W / "50b1c1d4f775c61:df3" 如果ETag没改变,则返回状态304然后不返回,这也和Last-Modified一样。 测试Etag主要在断点下载时比较有用。 Last-Modified和ETags如何帮助提高性能?/Etag 聪明的开发者会把Last-Modified和ETags请求的http报头一起使用,这样可利用客户端(例如浏览器)的缓存。因为服务器首先产生Last-Modified/Etag标记,服务器可在稍后使用它来判断页面是否已经被修改。本质上,客户端通过将该记号传回服务器要求服务器验证其(客户端)缓存。 过程如下: 1.客户端请求一个页面(A)。 2.服务器返回页面A,并在给A加上一个Last-Modified/ETag。 3.客户端展现该页面,并将页面连同Last-Modified/ETag一起缓存。 4.客户再次请求页面A

If-Modified-Since HTTP header passed by IE9 includes length?

五迷三道 提交于 2020-01-24 04:00:16
问题 Please clarify this weird If-Modified-Since header passed by IE9 In my ASP.NET 4.0 web app, I've got a generic handler (.ashx) that serves images stored in the DB. In the interest of efficiency, I'm handling some caching-related headers and passing cache information. I'm getting DateTime parse errors moderately frequently from trying to parse the If-Modified-Since header contents, usually from IE9. Turns out it's sending something like this: Mon, 28 Nov 2011 16:34:52 GMT; length=8799 I'm

How do I get the last modification time of a Java resource?

落花浮王杯 提交于 2020-01-24 02:08:48
问题 Can someone please tell me a reliable way to get the last modification time of a Java resource? The resource can be a file or an entry in a JAR. 回答1: If you with "resource" mean something reachable through Class#getResource or ClassLoader#getResource, you can get the last modified time stamp through the URLConnection: URL url = Test.class.getResource("/org/jdom/Attribute.class"); System.out.println(new Date(url.openConnection().getLastModified())); Be aware that getLastModified() returns 0 if

Is it possible to reset the last modified date of an Android file?

青春壹個敷衍的年華 提交于 2020-01-23 17:54:22
问题 I'm writing a purge function for our software that removes all image files that haven't been used in over a month. To do this, I am checking two things: the last-modified date of the file a query on a database that shows recently viewed files. The query is much slower than the file check. So I would ideally like to be able to reset the last modified date on any files that fail the first check, but pass the second, so that (for example) a list of venerable but often-used files aren't gradually

Getting last modified date of a file not the last created date in Java

蓝咒 提交于 2020-01-15 11:36:37
问题 I had copied a file to my android device. When i check it's last modified date with file.lastModified() it returns the date the file was created which is just now. I want the original date when the file was last modified and not copied. I can see this date in windows explorer with the tag Date modified .The file.lastModified() matches with the Date created Tag of the file. If i could get the last Modified Date i can update the file with another file from server after it has been updated by

Getting last modified date of a file not the last created date in Java

ε祈祈猫儿з 提交于 2020-01-15 11:31:46
问题 I had copied a file to my android device. When i check it's last modified date with file.lastModified() it returns the date the file was created which is just now. I want the original date when the file was last modified and not copied. I can see this date in windows explorer with the tag Date modified .The file.lastModified() matches with the Date created Tag of the file. If i could get the last Modified Date i can update the file with another file from server after it has been updated by

File.lastModified() painfully slow!

烈酒焚心 提交于 2020-01-14 10:22:49
问题 I'm doing a recursive copy of files and like xcopy /D I only want to copy newer files destination files (I cannot use xcopy directly since I need to alter some files in the copy process). In java I use lastModified() to check if the destination file is older than the source file and it's very slow. Can I speed up the process (maybe using JNI??)? Are there any other copy scripts that can do the job better (copy new files + regexp change some text files)? Copying files anyways is not an option

File.lastModified() painfully slow!

我们两清 提交于 2020-01-14 10:21:12
问题 I'm doing a recursive copy of files and like xcopy /D I only want to copy newer files destination files (I cannot use xcopy directly since I need to alter some files in the copy process). In java I use lastModified() to check if the destination file is older than the source file and it's very slow. Can I speed up the process (maybe using JNI??)? Are there any other copy scripts that can do the job better (copy new files + regexp change some text files)? Copying files anyways is not an option

how to tell when a HTTP web page has changed when it is of type html/text?

允我心安 提交于 2020-01-14 06:10:49
问题 I'm trying to work out the algorithm to tell if non-binary files on the web have changed or not. I was going to go with: LastModified datetime from header, and then if these aren't present fallback to ContentLength from header I'm finding however that for alot of websites the LastModified for the HTML pages are actually just using the current DateTime, hence the approach doesn't work (i.e. would lead to an indication that the page is always changing) I think...? What would be a good algorithm