أضف رؤوس انتهاء الصلاحية في PHP لا يمكن جعلها تعمل

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

سؤال

أملك yslow الإضافية المثبتة

alt text

عندما أتحقق من طلبي في yslow أحصل عليه أضف الرؤوس الصالحة الصلاحية الذي لا أعرفه

alt text

لقد بحثت عن الأسئلة ذات الصلة في SO وكذلك Google وجدت هذه الطريقة مناسبة

<?
    header("Expires:".gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    ob_start();
    session_cache_limiter('public');
    session_start();
?>
<html>

ولكن لا يزال يظهر لي نفس الشيء

بما أنني مبتدئ ، فأنا لا أعرف الكثير عن .htaccess

الرجاء مساعدتي في تحسين أداء التطبيقات

شكرا لك مقدما

واززي

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

المحلول

سيؤدي ذلك فقط إلى تعيينه لمحتوى صفحتك وليس أشياء مثل الصور وملفات CSS ، لقد لاحظت على لقطة الشاشة الخاصة بك أنها تقول 42 ملفًا ، ومن المفترض أن هذه الصور الخاصة بك ، CSS ، JS إلخ.

جرب هذا في ملف .htaccess الخاص بك ، لاحظ أن هذا سيعمل فقط إذا كان لديك mod_expires و mod_headers تمكين في أباتشي:

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"  
</ifModule>

<ifModule mod_headers.c>
  <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\\.(xml|txt)$">
    Header set Cache-Control "max-age=216000, public, must-revalidate"
  </filesMatch>
  <filesMatch "\\.(html|htm|php)$">
    Header set Cache-Control "max-age=1, private, must-revalidate"
  </filesMatch>
</ifModule>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top