Khi một người duyệt web bất kỳ vào trang web của bạn, trình duyệt của anh ta sẽ lưu trữ tạm thời (cache) những hình ảnh, HTML, CSS và các tập tin khác. Nếu phần Header trong trang của bạn có Last-Modified, thì lần kế tiếp khi anh ta truy cập vào web của bạn, máy chủ sẽ kiểm tra xem trang web của bạn có sự thay đổi kể từ lần cuối cùng anh ta vào hay không?
Nếu không, máy chủ sẽ trả về mã 304 Not Modified để thông báo cho trình duyệt là không có thông tin thay đổi và hãy tải trang từ trong cache.
Các trang HTML (chúng tôi đang nói đến các trang web tĩnh), Last-Modified là thời gian sau cùng bạn thay đổi trang HTML cụ thể nào đó hoặc thậm chí chỉ bạn tải một trang HTML về sau đó up lên lại máy chủ là Last-Modified đã được cập nhật (xem hình bên dưới).
Các trang HTML (chúng tôi đang nói đến các trang web tĩnh), Last-Modified là thời gian sau cùng bạn thay đổi trang HTML cụ thể nào đó hoặc thậm chí chỉ bạn tải một trang HTML về sau đó up lên lại máy chủ là Last-Modified đã được cập nhật (xem hình bên dưới).
Kiểm tra Last-Modified hiện tại của trang http://ctit-vn.com
Tải về và chỉ up lên lại máy chủ ...
Kết quả là Last-Modified đã thay đổi
Tuy nhiên, các trang web động - những trang lấy dữ liệu từ cơ sở dữ liệu thì có đôi chút phức tạp. Máy chủ không biết cách các trang động tạo ra dữ liệu như thế nào hoặc làm cách nào dữ liệu có thể thay đổi từ lần cuối cùng nó được nạp.
Bạn có thể tham khảo nguyên văn về vấn đề này tại apache.org:
When Apache serves a static web page, it will also issue a "Last-modified" header to the requesting client (such as a visitor's web browser). This "Last-modified" header tells the browser (or proxies or other clients) the date that the document was last changed. It allows browsers and proxies to know when it must reload the document to get the latest version. The header is not issued when a dynamically generated document is served - that is, it is not served when documents with server side includes (SSI) (such as *.shtml documents) and documents generated by scripts (such as PHP or Perl) are served.
When you use either of the above methods to serve your dynamic pages, the web server will also not generate this "Last-modified" header even though it may appear to your visitors as though it is receiving a ".html" file.
Bạn có thể tham khảo nguyên văn về vấn đề này tại apache.org:
When Apache serves a static web page, it will also issue a "Last-modified" header to the requesting client (such as a visitor's web browser). This "Last-modified" header tells the browser (or proxies or other clients) the date that the document was last changed. It allows browsers and proxies to know when it must reload the document to get the latest version. The header is not issued when a dynamically generated document is served - that is, it is not served when documents with server side includes (SSI) (such as *.shtml documents) and documents generated by scripts (such as PHP or Perl) are served.
When you use either of the above methods to serve your dynamic pages, the web server will also not generate this "Last-modified" header even though it may appear to your visitors as though it is receiving a ".html" file.
Không có nhận xét nào:
Đăng nhận xét