简体   繁体   English

如何在不使用htaccess的情况下解决利用wordpress中的浏览器缓存问题

[英]How to solve Leverage browser caching in wordpress without using htaccess

I have a website made with WordPress and Windows Plesk panel hosting. 我有一个使用WordPress和Windows Plesk面板托管制作的网站。 Most of these type of hosting do not support htaccess due to IIS. 由于IIS,大多数此类托管不支持htaccess。

I want to solve Leverage browser caching in wordpress without using htaccess file. 我想在不使用htaccess文件的情况下解决在wordpress中利用浏览器缓存的问题。

I have tried below non htaccess caching thing but the site is displaying blank screen. 我曾尝试以下非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;
?>

Hi You can do below things to achieve A Grade in Gtmetrix by doing the below things. 嗨,您可以做以下事情,以取得Gtmetrix的A级成绩。

some hosting provider do not like htaccess and therefore I preferred go for Hyper Cache plugins, and do all necessary configurations. 一些托管服务提供商不喜欢htaccess,因此我更喜欢使用Hyper Cache插件,并进行所有必要的配置。

Then Add below things in header.php of your Wordpress themes. 然后在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;
?>

After check and do let me know. 经过检查,并让我知道。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM