Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does header("Expires: 0") do? [duplicate]

Tags:

http

php

Can anyone explain this?

like image 219
Mohsin Sheikh Khalid Avatar asked Dec 23 '10 05:12

Mohsin Sheikh Khalid


People also ask

What does expires header mean?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.

Should I add expired headers?

Expires headers can help you control how different file types are cached and served to your visitors. They can not only help improve load times for returning visitors but also ensure they're only seeing fresh content. That's why they're important to website speed and the overall user experience.

Where do I put expired headers?

If your web host uses the Apache web server, you can add Expires headers using the . htaccess file, which is located in the root folder of your server (the same folder that holds the wp-config.

HOW use expired header in HTML?

Expires Headers are certain lines of code that tell your browser how long it should keep the cached files from your site. You can add Expires Headers by adding a code such as ExpiresByType image/jpg “access plus 1 month” to your site.


2 Answers

Generally used to prevent caching. However, this document will probably provide you with a better explanation:

http://download.oracle.com/docs/cd/E13158_01/alui/wci/docs103/devguide/tsk_pagelets_settingcaching_httpexpires.html

To quote:

Never use Expires = 0 to prevent caching. The Expires header is sent by the remote server and passed through to the browser by the Portal Server. Unless the time on all three machines is synchronized, an Expires=0 header can mistakenly return cached content. To solve this problem, set the Expires header to a fixed date that is definitely in the past.

like image 173
RabidFire Avatar answered Oct 12 '22 22:10

RabidFire


How caching works (among other things) is that you send a header to the browser telling it when the page's content will expire. This means that if you send a header like:

header("Expires Sunday June 10th 2011"); // not correct timestamp

The content won't 'expire' until that date. The browser can then use caching techniques to serve the page locally from your browser instead of having to download all the content again.

When you set the expiration to 0, it ensures that the next time the browser loads the page, it will download the content, thus giving you up to the second data. However, as you might see from other answers, you shouldn't send 0 to prevent caching, but instead send a date that is in the past.

like image 24
Tyler Carter Avatar answered Oct 12 '22 23:10

Tyler Carter