Cara mengaktifkan header kedaluwarsa di Apache

Cara mengaktifkan header kedaluwarsa di Apache

Caching browser digunakan untuk menyimpan file di cache browser pengguna akhir dan penggunaan kembali pada permintaan berulang. Itu secara signifikan meningkatkan waktu pemuatan halaman. Apache Web Server menyediakan modul MOD_EXPIRE. Yang mengontrol pengaturan header HTTP dan untuk kedaluwarsa dan arahan maksimal dari header HTTP kontrol cache di respons server.

Pengaturan kedaluwarsa header di Apache

Sebelum menggunakan ini, Anda harus memiliki modul kedaluwarsa mod yang diaktifkan di server apache. Pada Sistem Berbasis Debian (Ubuntu, Debian dan Linuxmint) Modul Kedaluwarsa dinonaktifkan secara default. Anda dapat mengaktifkan ini dengan menjalankan perintah berikut:

Sudo A2Enmod kedaluwarsa 

Setelah mengaktifkan modul, restart server Apache untuk memuat pengaturan baru.

Sekarang, tambahkan pengaturan di bawah ini ke file konfigurasi host virtual apache, atau tambahkan ini .file htaccess di bawah aplikasi Anda.

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 Aplikasi ExpiresByType/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 Berpalu Audio/Ogg A31536000 Berlalu Aplikasi TypyType/PDF A31536000 Berakhirnya Image/Png A31000 Audio/X3000 Audio/X35000 A31536000 ExpiresByType Image/TIFF A31536000 EXPIRESBYTYPE APLIKASI/X-FONT-TTF A31536000 ExpireSbyType Audio/WAV A31536000 Aplikasi Audio/WMA Audio-WOFF A34000 ExpireSbyType Audio/WMA AUDIO/WMA4000 Audio Audio Audio/WMA A34000 ExpiresByTypeWOFF2 A31536000 Aplikasi ExpiresByType/ZIP A31536000
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 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 Aplikasi ExpiresByType/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 Berpalu Audio/Ogg A31536000 Berlalu Aplikasi TypyType/PDF A31536000 Berakhirnya Image/Png A31000 Audio/X3000 Audio/X35000 A31536000 ExpiresByType Image/TIFF A31536000 EXPIRESBYTYPE APLIKASI/X-FONT-TTF A31536000 ExpireSbyType Audio/WAV A31536000 Aplikasi Audio/WMA Audio-WOFF A34000 ExpireSbyType Audio/WMA AUDIO/WMA4000 Audio Audio Audio/WMA A34000 ExpiresByTypeWOFF2 A31536000 Aplikasi ExpiresByType/ZIP A31536000

Membuat perubahan .htaccess akan segera efektif, tetapi jika Anda menambahkan pengaturan di atas dalam file konfigurasi host virtual apache, Anda perlu memuat ulang server apache.

Kesimpulan

Dalam tutorial ini, Anda telah belajar untuk mengaktifkan modul Apache dan mengkonfigurasi header HTTP Apache untuk menyimpan file di browser pengguna.