Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How to Enable expire headers in Apache

    How to Enable expire headers in Apache

    By RahulMay 25, 20201 Min Read

    Browser caching is used to save files on end user browser cache and re use on recurring requests. It significantly improve the page load times. Apache web server provides module mod_expire. Which controls the setting of the HTTP header and for expires and max-age directive of the Cache-Control HTTP header in the server responses.

    Advertisement

    Setup Expire headers on Apache

    Before using this, you must have mod expires module enabled on Apache server. On the Debian based systems (Ubuntu, Debian and Linuxmint) expires module is disabled by default. You can enable this by running the following command:

    sudo a2enmod expires
    

    After enabling modules, restart Apache server to load new settings.

    Now, Add the below settings to Apache virtual host configuration file, or add this in .htaccess file under your application.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType text/css A31536000
        ExpiresByType text/x-component A31536000
        ExpiresByType application/x-javascript A31536000
        ExpiresByType application/javascript A31536000
        ExpiresByType text/javascript A31536000
        ExpiresByType text/x-js A31536000
        ExpiresByType text/html A3600
        ExpiresByType text/richtext A3600
        ExpiresByType text/plain A3600
        ExpiresByType text/xsd A3600
        ExpiresByType text/xsl A3600
        ExpiresByType text/xml A3600
        ExpiresByType video/asf A31536000
        ExpiresByType video/avi A31536000
        ExpiresByType image/bmp A31536000
        ExpiresByType application/java A31536000
        ExpiresByType video/divx A31536000
        ExpiresByType application/msword A31536000
        ExpiresByType image/gif A31536000
        ExpiresByType application/x-gzip A31536000
        ExpiresByType image/x-icon A31536000
        ExpiresByType image/jpeg A31536000
        ExpiresByType image/webp A31536000
        ExpiresByType application/json A31536000
        ExpiresByType audio/midi A31536000
        ExpiresByType video/quicktime A31536000
        ExpiresByType audio/mpeg A31536000
        ExpiresByType video/mp4 A31536000
        ExpiresByType video/mpeg A31536000
        ExpiresByType video/webm A31536000
        ExpiresByType application/x-font-otf A31536000
        ExpiresByType audio/ogg A31536000
        ExpiresByType application/pdf A31536000
        ExpiresByType image/png A31536000
        ExpiresByType audio/x-realaudio A31536000
        ExpiresByType image/svg+xml A31536000
        ExpiresByType application/x-shockwave-flash A31536000
        ExpiresByType application/x-tar A31536000
        ExpiresByType image/tiff A31536000
        ExpiresByType application/x-font-ttf A31536000
        ExpiresByType audio/wav A31536000
        ExpiresByType audio/wma A31536000
        ExpiresByType application/font-woff A31536000
        ExpiresByType application/font-woff2 A31536000
        ExpiresByType application/zip A31536000
    </IfModule>

    Making changes in .htaccess will will be effective immediately, But if you add above settings in Apache virtual host configuration file, you need to reload Apache server.

    Conclusion

    In this tutorial, you have learned to enable Apache modules and configure Apache HTTP headers to save files on users browser.

    Apache Headers
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install Apache CouchDB on Ubuntu & Debian

    Nginx vs. Apache: Comparing the Two Leading Web Servers

    Nginx vs. Apache: Comparing the Two Leading Web Servers

    How to Set Up Apache, MySQL, and PHP on macOS: A Comprehensive Guide

    View 1 Comment

    1 Comment

    1. Mario on June 16, 2020 3:36 pm

      Thanks…

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting and Getting the Default Timezone in Python
    • What is Media Access Control (MAC) Address?
    • What is Cross-Site Scripting (XSS)?
    • What is Content Security Policy (CSP)?
    • A User’s Guide to Understanding Redirection Operators in Bash
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.