تنفيذ التحكم في ذاكرة التخزين المؤقت باستخدام .htaccess على خادم Apache

StackOverflow https://stackoverflow.com/questions/4619261

  •  30-09-2019
  •  | 
  •  

سؤال

حسنًا ، ما زلت أحاول الحصول على رأسي حول بعض الأشياء التخزين المؤقت وقد مررت ببعض الأمثلة التي يمكنني العثور عليها على Google. لقد أضفت الكود التالي إلى ملف .htaccess الخاص بي:

### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
ExpiresByType image/gif "access plus 3 months"
ExpiresByType image/png "access plus 3 months"
ExpiresByType image/jpg "access plus 3 months"
ExpiresByType text/javascript "access plus 3 months"

باستخدام أدوات تدقيق Chrome وأداة YSLow Firebug ، يبدو أن هذا يخطط لبعض الصور/الملفات ، ولكن ليس كلها جميعًا. لا يزال لدي قائمة بالملفات (.jpg و .js و .css - أعلم أنني لم أعدد ملفات CSS على ذاكرة التخزين المؤقت هنا) التي لا تتخزين مؤقتًا. الرسالة في مراجعة Chrome تنص ببساطة The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers:

بعض الصور التي لا تتخلف عن التخزين المؤقت هي صور خلفية ، والبعض الآخر جزء من معرض JS ويتم استدعاؤه عبر JS - هل يمكن أن يؤثر ذلك على سبب عدم التخزين المؤقت؟

آسف ، لا يمكنني إعطاء رابط للرمز - لا تزال المواقع تحت اللف ويقتصر على عرض العميل فقط.

شكرا مقدما!

هل كانت مفيدة؟

المحلول

يبدو أنك كتبت خطأ من نوع MIME:

# enable expirations
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/pjpeg "access plus 1 week"
ExpiresByType text/javascript "modification plus 1 week"
ExpiresByType application/javascript "modification plus 1 week"
ExpiresByType text/css "modification plus 1 week"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top