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

Doctype check failure edge case #341

Open koskinenaa opened 2 months ago

koskinenaa commented 2 months ago

Issue: The $html_doctype_regex check in Cache_Enabler_Engine::is_cacheable() fails, if there's a HTML comment before the <!doctype html> tag.

Backgroud: I installed the plugin to a site I manage and was puzzled why the site wasn't getting cached. After some digging and stepping through the plugin source code one step at a time I figured out that the content was not cacheable due to $html_doctype_regex check failing.

The site in question uses a theme developed by a 3rd party. They've added their logo as a HTML comment before the <!doctype html>. The regex apparently expects the doctype to be the first thing in the source content and so the check fails due to the preceding comment.

Solution: Although this is just one edge case and easy to fix by removing the unneccesary comment, I wanted to let you know about in case you decide to tweak the regex to take into account any extra characters before the doctype tag. Unfortunately regex is like black magic to me so I don't have anything to propose how to tweak it.

Suggestion: It would be nice, if the plugin had some kind of logging or debugging feature, which would tell you why the caching failed. It might save some time in figuring out what's wrong with the site in situations like the above.