The Last-Modified HTTP header tells the client the time last change page (object). If the client (browser, search robot) received the Last-Modified header, then the next time the address is accessed, provided that the page (object) is in the local cache, it will add an If-Modified-Since question (whether the page has changed since the date received in Last-Modified). In turn, the server, having received the If-Modified-Since request, must check the received timestamp with the time the page was last modified and, if the page has not changed, respond with 304 Not Modified.

Traffic Saving

If the page has not changed, the server will stop transmitting data after sending headers with the 304 Not Modified code; the page body, images and other objects will not be transmitted.

Reducing server load

Correct implementation of checking the last page modification time can significantly (up to 30% or more) reduce the load on the server. Correct implementation means checking the time before the page is generated on a dynamic site. In this case, all actions to generate the page (querying content from the database, parsing templates, receiving comments, etc.) will not be performed. This is especially true for sites with high attendance and the long duration of the user's visit. Example: a user is on a sports news site and is constantly updating home page awaiting publication of the match result. In a few minutes, a page can be requested and received dozens of times. If the Last-Modified header is sent and the If-Modified-Since request is processed correctly, then the page will actually be submitted once, and all subsequent requests will receive a 304 Not Modified response.

Speed ​​up indexing by search engines

Search engines, through their webmaster guidelines, recommend sending the Last-Modified header and properly handling If-Modified-Since .


Make sure your web server supports the If-Modified-Since HTTP header. This header will allow the web server to tell Google whether the site's content has changed since the last time it was crawled. Supporting this feature will reduce bandwidth usage and costs.

Make sure your http headers are correct. In particular, what is important is the content of the response that the server gives to the if-modified-since request. The Last-Modified header must indicate the correct date the document was last modified. If the server does not display the last modification date of the document, your site will be indexed, but:
- the search results will not show the date next to the pages of your site;
- when sorting by date, the site will not be visible to most users;
- the robot will not be able to obtain information about whether the site page has been updated since the last indexing. And since the number of pages a robot receives from a site in one visit is limited, changed pages will be reindexed less often.

I didn’t feel sad until I installed the Seo Scan plugin today. A good plugin that shows what Google may not like about your site and server. And there was one thing I didn’t like about my site for sure - the lack of last-modified .


A little theory, I just found out about it today. Last-modified is an http header that sends a signal about whether there have been changes on such and such a page or not, sending an If-Modified-Since response with a 304 code. Something like this...

Although without all this the site will be indexed, as Yandex says, there are also significant disadvantages in the absence of this header:

  • the search results will not show the date next to the site pages;
  • when sorting by date, the site will not be visible to users;
  • the robot will not be able to obtain information about whether the site page has been updated since the last indexing. And since the number of pages a robot receives from a site in one visit is limited, changed pages will be reindexed less often.

As you can see, there are many disadvantages, and first of all, it is not very fast indexing and re-indexing of the site. That is, you made a USEFUL change to the article, and now I make a lot of them every day, and Yandex and Google can see It's only in a couple of months! No, we don’t need this kind of hockey, now I’ll smash myself into pieces and fix this shortcoming!

How to check last-modified?

You can check in different ways, in wordpress the easiest thing is to install the above plugin SEO Scan, it gave me this:

It’s also acting up, but that’s another story, then I’ll dig deeper into that too. You can also check last-modified through a service of the same name last-modified.com


As you can see, it also shows the absence of a response If-Modified-Since - Last Modified not found! Or you can use the Yandex service Checking the server response


It's the same here - HTTP status code:“304 Not Modified” means the system is not working. Although after some time the obvious error disappeared, the 304 response code never appeared.

I immediately became interested, does this even work for anyone? I decided to check this with those bloggers who themselves wrote manuals on this topic:


Yes, the guy from the TOP found Last-Modified for this request, which means it’s possible for me too. By the way, his article lists many ways to configure Last Modified, let's try them, although I found others.

How to configure last-modified?

I will describe all the methods that I tried and immediately say whether it worked for me or not. But keep in mind that if it doesn’t work for me, it doesn’t mean it won’t work for you.

1. The first method is to install the plugin

The easiest way for those who have WordPress is to install plugins designed for this, for example: Add Headers, If Modified Since or If Modified Since Header.

None of these plugins worked for me, I don’t know why. Maybe it will work for you?

2. Second method - PHP code

Service last-modified.com, described above, suggests placing the following php code in the header.php file, at the very beginning:

= $LastModified_unix) ( header($_SERVER["SERVER_PROTOCOL"] . " 304 Not Modified"); exit; ) header("Last-Modified: ". $LastModified); ?>

It didn't help me either. I also suggest trying to place it in the index.php file in the root of the site, but this didn’t help me either.

3. The third method is writing in .htaccess

If you have an Apache server, then most likely this will work for you. Needed in file .htaccess in the root of the site paste the code:

RewriteRule .* - RewriteRule .* -

It didn’t work for me, because I have a combination of Ngnix + Apache and all these manipulations with .htaccess most often do not work.
After all this torment I thought: why am I the only one suffering? I’ll write to the hosting support service, the people there are competent, maybe they can give me some advice? I wrote and am sitting and waiting.

I received a response from technical support:

It's simple. The pages of your site are generated by PHP scripts that do not display this header to the browser.
The web server (nginx) for static files (jpg, gif, css, js, etc.) displays the date of the last modification of the file in the last-modified header. Examples in screenshots.
If you do not have very high site traffic, then there is no point in caching site pages on the browser side.

Note: The adaptive version of the site is activated, which automatically adapts to the small size of your browser and hides some details of the site for ease of reading. Enjoy watching!

Hello dear blog readers We continue the topic, one of the most important SEO factors. This article will touch on what can be called the intricacies of on-page optimization, since we will talk about the response code that search engines and visitors will receive in response to their access to the page.

Correct server response

Despite the fact that this is a rather small detail when building and optimizing the site as a whole, it is very important! Namely, it is important that a page on which there have been no changes since the last visit of a robot or a person gives a 304 code, which means that the page has remained unchanged. When the server gives this code to the client, the execution of all PHP scripts on the page does not even begin; instead, the page is loaded from the cache, which significantly reduces the load on the server and speeds up page loading for the user.

Thus, by setting up the correct responses from our server, we kill at least five birds with one stone:

  • We speed up page loading for visitors (people).
  • We reduce the load on the server.
  • The date will be shown in the search results (for Yandex for sure) latest update page, which can attract the user's attention, especially if the date is recent.
  • Site pages will be involved in sorting search engines by date.
  • We significantly speed up the indexing of your site by search engines!

For some reason for me last point seems the sweetest (as it affects SEO and increases the credibility of your site among search engines), although without a doubt the other points are also extremely important.

How to configure 304 and 200 server responses?

We have already said that in response to a request to unchanged pages, the server must return 304 Not Modified, and what code should the server give if the client accesses the page for the first time or accesses a changed page? In such cases, the server must give the status 200 OK. There is no need to send this code specifically; if everything is in order with the page, then it always displays 200.

Therefore, we only need to take care of the 304 code, since the server will not send it without our intervention. To do this, the title will help us Last-Modified and request .

Headings Last-Modified

Last-Modified is the header we send with using PHP, this header contains the exact time the page was last modified (in seconds). For this purpose, a generally accepted measure of time is used: Unix Time Stamp.

Unix time stamp is the number of seconds that have passed since the beginning of the Unix era: January 1, 1970. At the time of writing this sentence, the Unix time stamp is equal to 1370597447 seconds - this is 06/07/2013 09:30:47 GMT (+00:00).

That is, all we need to do is just send a PHP header with instructions Last-Modified and the desired date:

Header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");

Where header is a construct for sending an HTTP header, Last-Modified– what we send and immediately after the colon comes its value:

Gmdate("D, d M Y H:i:s", $last_modified_time)." GMT".

The Last Modified value is the function gmdate(), which contains a variable I invented $last_modified_time(you can call it whatever you want). In variable $last_modified_time and contains the time of the last change in the format Unix Time Stamp, and the function gmdate() serves us to bring the date into proper form (Greenwich Mean Time).

For clarity, here is an example: if we use a function gmdate() let's put the value 1365003142 , then the output will be: Wed, 03 Apr 2013 15:32:22.

Now that we have learned how the whole process works, the question may arise: “Do we have to manually specify the last modified time for each page?” Answer: “Yes!” Personally, I do exactly this - manually, the most reliable option. However, specifically for this blog, I have provided for everything, for example, if a new comment appears on the page, then in the variable $last_modified_time The time this comment was added is recorded so that search engines can index new comments and know that the site is “live.” Each site is individual and you will have to come up with your own algorithm for indicating the date the page was last modified, or always specify it manually.

Let me emphasize again, my algorithm is as follows:

1) I indicate the date of creation of the material manually; if I change something in the article (typos or additions), then I again manually enter the new time of the last update.

2) If the visitor adds a comment, then in the variable $last_modified_time automatically, without my knowledge, the time the comment was added is entered, since in fact this will be the date the page was last modified.

What I didn’t take into account: in the right column of the site I have latest articles, recommended And top 10. They change constantly and at the same time for all pages. If, every time I changed the right column of the site, I changed (automatically or manually - it doesn’t matter) the date of the last page change, then the whole meaning of this action would be lost. I decided that these changes should be tracked and taken into account when specifying $last_modified_time not worth it, as they have no SEO benefits.

As I wrote before, I can't tell you exactly how to automate the last modified date of a page, but I will tell you how NOT to do it!

Errors when specifying the last modified date

The first thing that might come to mind for most people is to send the date of the last modification of the file with the contents of the page in the header. Personally, I have the texts of articles in files, and not in a database, so for me this method might seem like an excellent way out of not having to enter it every time Unix Time Stamp manually. But no! Most hosting sites, and maybe even all of them, take the date of its creation as the date of the last change of a file; they do not take into account subsequent changes.

I think the consequences in such cases are clear to you. One popular Ukrainian hosting provider (and I think he’s not the only one) in his FAQ writes something like: “Instead of the date the file was last modified, use the function time(), which returns the current time in Unix time stamp format." This is so absurd! He'll just shoot himself on the spot! And this hosting provider is considered “one of the best”, after I read this, I immediately became a client of theirs.

This is just anti-SEO, think for yourself, a search engine comes to your page and looks: “Wow! The last time the page changed was just now, I guessed when to come, great!” A couple of days later he comes to this same page: “Look, it just changed again, what a coincidence... Wait, why don’t I see any changes? Okay, I’ll come another time.” He comes again: “Well, no, guys, this is no longer funny, you definitely can’t be trusted.” This is such a fairy tale :)

And then people wonder why the results are search results not as we would like, but because your site is missing the banal trust(trust). Just like in the parable “About the Shepherd and the Wolves.”

So, we’ve sorted out the main errors: you cannot specify the current time and I do not recommend specifying the file modification time. Now let's continue to look at how it all works.

Configure sending headers Last-Modified this is exactly 1/3 of the work, we still have to: make a response to the request and enable page caching. Both of these actions will not take much time and lines of code.

is a client request to your server, in which the client asks: “has the page changed since my last visit?” If the page has not changed, then we must stop further loading of the page with the command:

In this case, the body of the page should not begin to be drawn, this all happens BEFORE the first output of anything to the page! At the same time, it is necessary to return the server response to the client 304 Not Modified, thereby saying that the page needs to be taken from the cache. Let's get straight to the point:

If (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) >= $last_modified_time)( header("HTTP/1.1 304 Not Modified"); die; ) header("Last-Modified : ".gmdate("D, d M Y H:i:s", $last_modified_time).");

So, in the first line, we check whether the HTTP_IF_MODIFIED_SINCE request has arrived to our server, and we also immediately check the number of seconds in the incoming HTTP_IF_MODIFIED_SINCE is greater than in $last_modified_time or not? If it is greater, then the date of the last visit of the client is later than the date of the last change of the page, from here we draw a purely logical conclusion that the page has not changed, which means we send the server response in the second line 304 Not Modified and with line 3 we kill (stop) the execution of all scripts on the page. In other words, we stop downloading it.

If the client did not send us the HTTP_IF_MODIFIED_SINCE request or his last visit was earlier than the date the page was last modified, then we (by default) send the code 200 OK and in the fifth line we send him the CURRENT date of the page change, instead of the one he had.

I told you everything you need about IF_MODIFIED_SINCE and how the code works, except what the strtotime() function does:

Strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"])

An attentive and savvy reader could already guess that this function converts an ordinary date into a Unix time stamp, since we set the $last_modified_time variable in it, and therefore for comparison we need to bring everything to a common denominator common system measurements.

And lastly, all we have to do is enable caching, this is done using the following lines:

Header("Cache-Control: public"); header("Expires: " . date("r", time()+10800));

Where the number 10800 is the time (in seconds) for which we want to cache the page, that is, in this example, 3 hours.

And as always, for those who don’t understand anything, I’ll post everything in full, as it’s done on my blog:

= $last_modified_time)( header("HTTP/1.1 304 Not Modified"); die; /* killed everything below */) header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT"); ?> And off went the rest of the page

I think you might have noticed that this whole Last-Modified story is an analogue of the tag in -. So lastmod is for informational and advisory purposes only, and no one can argue with your server’s answers. Naturally, it is not uncommon for the lastmod in the sitemap to differ from the Last-Modified header, but from now on they should be the same for you! After all, what kind of science have we now studied, not in order to be like unfortunate webmasters who have not advanced further than sitemap.xml.

Personally, I don't use the lastmod tag at all in my sitemaps at the moment, maybe later I'll reconsider what I'm doing, but for now I don't see the point in being so meticulous about having the right headers Last-Modified :)

And finally, check the correctness Last-Modified and you can using this service: click .

Thank you for your attention, special thanks to the ever-growing number of subscribers, for me this is the greatest incentive to write on the blog more often. So, whoever hasn’t subscribed to new articles yet, welcome!

HTTP header Last-Modified (last changes) transmits to the client the time of the last change of the document (web page). The client (browser or search robot) sends the header " If-Modified-Since" and if the date the page was last modified matches, the server returns the header " 304 Not Modified" and doesn't load the page. If the last modified time is different (or the last modified header is not configured) - the server returns the header " 200 OK" and loads the page. That is, instead of reloading the page again and updating the cache, the client only receives header 304. The client saves traffic, and the server sends less data - mutual savings.

But why would there be this article if not to talk about the benefits that setting the Last-Modified header brings for, or more precisely, for speeding up site indexing. It is not difficult to guess that 10 pages of a site will be indexed faster than 1000. The same principle that allows you to optimize page loading also works for indexing. Search engine you don't need to index 1000 pages to find 10 new pages. Thanks to last modified, we leave only new pages (or updated ones) for the robot. The robot comes to the site and first takes what it needs, and then everything else.

Setting the Last-Modified header

Make sure your http headers are correct. In particular, what is important is the content of the response that the server gives to the “if-modified-since” request. The Last-Modified header must indicate the correct date the document was last modified. Even if the server does not display the last-modified date of the document, your site will be indexed. However, in this case, you should consider the following: - the search results will not show the date next to the pages of your site; - when sorting by date, the site will not be visible to most users; - the robot will not be able to obtain information about whether the site page has been updated since the last indexing. And since the number of pages a robot receives from a site in one visit is limited, changed pages will be reindexed less often. Make sure your web server supports the "If-Modified-Since" HTTP header. This header will allow the web server to tell Google whether the site's content has changed since the last time it was crawled. Supporting this feature reduces overhead and bandwidth usage.

Here are examples of how to configure the last-modified header to be sent and If-Modified-Since to be handled correctly.

How to set up meta Last-Modified for static html pages

How to set up Last-Modified in php

= $LastModified_unix) ( header($_SERVER["SERVER_PROTOCOL"] . " 304 Not Modified"); exit; ) header("Last-Modified: ". $LastModified); ?>

How to configure Last-Modified .htaccess

RewriteRule .* - RewriteRule .* -

How to configure Last-Modified nginx + php

location ~ .php$ ( ... if_modified_since off; fastcgi_pass fcgi; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /<путь >/web$fastcgi_script_name; ... fastcgi_pass_header Last-Modified; include fastcgi_params; )

Check Last-Modified

When passing the header to the client is configured, it doesn't hurt check last modified for correctness. You can check Last-Modified on your own or a third-party website through online services.

Or make your own check for correct processing of the Last-Modified header:

Setting the Last-Modified header and processing the If-Modified-Since header will be extremely useful for any larger or smaller site. The processing speed of website pages can become significant. Relatively simple setup will not create problems, especially since for popular CMSs like joomla, wordpress, modx, etc. there are ready-made solutions.

Syntax

Last-Modified: , ::GMT

Directives

One of "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", or "Sun" (case-sensitive). 2 digit day number, e.g. "04" or "23". One of "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ( case sensitive). 4 digit year number, e.g. "1990" or "2016". 2 digit hour number, e.g. "09" or "23". 2 digit minute number, e.g. "04" or "59". 2 digit second number, e.g. "04" or "59". GMT

Greenwich Mean Time. HTTP dates are always expressed in GMT, never in local time.

Examples

Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT

Specifications

Specification Title
RFC 7232, section 2.2: Last-Modified Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests

Browser compatibility

The compatibility table in this page is generated from structured data. If you"d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Last-ModifiedChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Close