keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

Cache http and https pages separately #50

Closed Thannoy closed 5 years ago

Thannoy commented 5 years ago

A single URI may be served as http or as https content.

In this case, both requests are likely to not serve the same content. The first one will contain many "http" links to website resources whereas the second will point them as https links.

https "mixed content" issue

Before this commit, a page cache was created the first time a URI was requested, and all next requests to this URI were answered with cached content, ignoring scheme. This especially led to "mixed content" issues when the cache contained http content, because a https page was answered with http links to resources.

Recent browsers then refuse to load those http resources leading to broken https website.

How this pull request try to fix this

This commit appends SERVER_PORT to cache file names so http and https pages are cached separately.

Implementation choices

SERVER_PORT has been chosen instead of a "http"/"https" token in cache file path for two reasons:

Possible improvements

A private function may be created in order to remove code duplication, and optionally easify the addition of other variants in the future (like SERVER_PROTOCOL, etc).

svenba commented 5 years ago

Having the complete site under HTTPS is recommended.