Konfigurasi Mod_Expires pada Apache
by servindo
Untuk meningkat performa website, selain mengaktifkan GZIP Compression, juga perlu mengaktifkan cache di browser. Selain dapat mengehmat bandwidth server dan client juga dapat memercepat proses loading sebuah website
Disini saya mensetting agar cache di simpan di browser client selama 1 bulan.
Anda bisa menambahkan baris konfigurasi pada setiap VirtualHost, mauapun pada file .htaccess
<IfModule mod_expires.c> <FilesMatch ".(jpe?g|png|gif|js|css)$"> ExpiresActive On ExpiresDefault "access plus 1 months" </FilesMatch> </IfModule>
Bagaimana agar setiap file type di cache dengan waktu berbeda? caranya seperti ini:
[...] <IfModule mod_expires.c> ExpiresActive on ExpiresByType image/jpg "access plus 60 days" ExpiresByType image/png "access plus 60 days" ExpiresByType image/gif "access plus 60 days" ExpiresByType image/jpeg "access plus 60 days" ExpiresByType text/css "access plus 1 days" ExpiresByType image/x-icon "access plus 1 month" ExpiresByType application/pdf "access plus 1 month" ExpiresByType audio/x-wav "access plus 1 month" ExpiresByType audio/mpeg "access plus 1 month" ExpiresByType video/mpeg "access plus 1 month" ExpiresByType video/mp4 "access plus 1 month" ExpiresByType video/quicktime "access plus 1 month" ExpiresByType video/x-ms-wmv "access plus 1 month" ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType text/javascript "access plus 1 week" ExpiresByType application/x-javascript "access plus 1 week" ExpiresByType application/javascript "access plus 1 week" </IfModule> [...]
Jika melakukan konfigurasi pada virtualhost, jangan lupa untuk merestart/mereload service apache nya, namun jika melakukan konfigurasi pada htaccess, maka tidak perlu merestart service apache.
Adapun lamanya waktu expires bisa menggunakan waktu:
- years
- months
- weeks
- days
- hours
- minutes
- seconds
Recommended Posts
Membuat Backup Automatis Database menggunakan Cronjob
November 22, 2017
Konfigurasi Master dan Slave DNS di CentOS
November 22, 2017
Full Backup Databases dan Restore Melalui Command Line
November 21, 2017