Automattic / Automattic/wp-super-cache

Super Cache: avoid garbage in browser and prevent downloading zipped page

Open
#987 0 comments 0 reactions 0 assignees View on GitHub
[Plugin] Super Cache enhancement
Dominant language
PHP
Stars
436
Forks
130
Avg merge
15h 11m
Merged PRs (30d)
10

Description

### Impacted plugin

Super Cache

### What

Prevent seeing garbage in the browser, and prevent downloading a zipped page, by amending .htaccess

### How

With reference to the readme.txt - Troubleshooting -

> 21. If you see garbage in your browser after enabling compression ...

If you disable mod_deflate, then Apache won't be able to compress .css, .js, etc files. Disabling mod_deflate is not an option for shared hosting, or those without admin access to their server. Instead of the recommendation to disable mod_deflate, I suggest preventing apache from zipping an already zipped file by amending the expert mode .htaccess file to add the rule:

```
# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule "\.html\.gz$" "-" [T=text/html,E=no-gzip:1]
```

following the existing rules:
`RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L]`

and:
`RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html.gz" [L]`

With reference to readme.txt - Troubleshooting -

> 9. If your browser keeps asking you to save the file after the super cache is installed ...

We need to tell Apache to set the correct encoding in the header by adding the directive to .htaccess like so:
```

# Serve correct encoding type.
Header append Content-Encoding gzip

# Force proxies to cache gzipped & non-gzipped html files separately.
Header append Vary Accept-Encoding

```
The above additions have been adapted from the Apache documentation at: https://httpd.apache.org/docs/2.4/mod/mod_deflate.html#precompressed

I am using these changes (albeit in my VirtualHost configurations rather than .htaccess) successfully on my own site(s):
https://nice.id.au/

See example attached:
[htaccess-with-changes.txt](https://github.com/Automattic/jetpack/files/11742048/htaccess-with-changes.txt)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.