1

I have a website made with WordPress and Windows Plesk panel hosting. Most of these type of hosting do not support htaccess due to IIS.

I want to solve Leverage browser caching in wordpress without using htaccess file.

I have tried below non htaccess caching thing but the site is displaying blank screen.

<?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;
?>
Sashi
  • 686
  • 8
  • 21
  • IIS works with web.config files, rather than .htaccess – Steve Oct 28 '15 at 21:54
  • Is there any way to achieve the Leverage browser caching, I did not find any web.config file in my host folder. – Sashi Oct 28 '15 at 21:56
  • http://stackoverflow.com/questions/2195266/how-to-configure-static-content-cache-per-folder-and-extension-in-iis7 I havent used IIS for a long time, so i cant be more specific. If in doubt why not ask your host? – Steve Oct 28 '15 at 22:01

1 Answers1

0

Hi You can do below things to achieve A Grade in Gtmetrix by doing the below things.

some hosting provider do not like htaccess and therefore I preferred go for Hyper Cache plugins, and do all necessary configurations.

Then Add below things in header.php of your Wordpress themes.

<?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!

Niharika Parida
  • 103
  • 1
  • 1
  • 16
  • Hi Its helps me to achieve A grade in GTmetrix and thank you for this, but could you please do let me know whats the use of . basename($filename) here ? – Sashi Oct 28 '15 at 22:28