[英]How to solve Leverage browser caching in wordpress pagespeed insight
[英]How to solve Leverage browser caching in wordpress without using htaccess
我有一個使用WordPress和Windows Plesk面板托管制作的網站。 由於IIS,大多數此類托管不支持htaccess。
我想在不使用htaccess文件的情況下解決在wordpress中利用瀏覽器緩存的問題。
我曾嘗試以下非htaccess緩存的東西,但該網站顯示空白屏幕。
<?php
if (isset($_GET['img'])) {$filename = $_GET['img'];}else{exit;}
$allowed = array('gif','png','jpg');
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed)) {exit;}
$stc = 31536000;
$ts = gmdate("D, d M Y H:i:s", time() + $stc) . " GMT";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header("Expires: $ts");
header("Cache-Control: max-age=$stc, public");
header("Pragma: cache");
ob_clean();
flush();
readfile($filename);
exit;
?>
嗨,您可以做以下事情,以取得Gtmetrix的A級成績。
一些托管服務提供商不喜歡htaccess,因此我更喜歡使用Hyper Cache插件,並進行所有必要的配置。
然后在Wordpress主題的header.php中添加以下內容。
<?php
$stc = 31536000;
$ts = gmdate("D, d M Y H:i:s", time() + $stc) . " GMT";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($filename));
header('Content-Transfer-Encoding: binary');
header("Expires: $ts");
header("Cache-Control: max-age=$stc, public");
header("Pragma: cache");
ob_clean();
flush();
exit;
?>
經過檢查,並讓我知道。
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.