InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Apache tutorials

  • AWStats on Ubuntu
  • ApacheBench - load testing
  • Auth to a location or directory
  • Block directory access using htaccess 404
  • Different expire Headers for multiple images
  • Disable directory listing
  • List loaded modules
  • Log Content-Type in access log
  • Log latency and host in apache log
  • Monitoring using mod_status
  • Python to analyze bots in logs
  • Remove php extension from url
  • egrep and access log
  • log custom data in apache access log
  • mod_rewrite
  • top IP list from access log
 
  • Home
  • > Tutorials
  • > Web Development
  • > Apache

How to set different HTTP Expire Header for multiple images of same type

By admin | Last updated on Mar 17, 2016

HTTP expire header can be used to set a expiry time for an image, css or any other content type. The browser does not fetch that content till it has crossed the expire timestamp. Common images are good candidates for setting expire time to some high value in future.

Sample expire header

Here is how an expire header looks like in HTTP response headers:

Expires: Sat, 27 Apr 2013 21:32:03 GMT

This header will mean that browser can cache this content till the date mentioned in the header. The higher the value, the better it is from performance and page speed perspective. Setting too high value will have downside that customer may see a stale image if the image is modified and image name is kept same.

Setting Expire header for all files a type

To set expire for all files of a specific type (e.g. image/png), here is the configuration you can use:

ExpiresByType image/png "access plus 14 days"

Setting expire header for specific files

Sometimes you may want to keep a high expire time for some selective images which appear on all pages. e.g. icons, etc. Here is an apache configuration to achieve that:

ExpiresActive On
<Files ~ "^(file1\.png|file2\.png)$">
  ExpiresByType image/png "access plus 14 days"
</Files>

This will set Expire Header only for file1.png and file2.png. In case you want to have different Expire header for some other files, you can add additional <Files> directive in Apache conf file.

Suggested posts:

  1. How to customize wordpress image alt tag
  2. CSS – inline-block and baseline alignment
  3. How to and why disable wordpress cron
  4. Linux – find files containing specific text
  5. Using JSLint on command line on Ubuntu linux – quick start guide
  6. How to include angularjs javascript in wordpress post
  7. How to redirect wordpress feed to feedburner feed url
  8. HTML form file upload hello world
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Apache, Tutorials, Webmaster
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress