Append a hash ?digest to CSS files for cache-busting - #108
Conversation
|
Thanks for reporting. Sphinx 3.4.3: Sphinx 6.1.3: Options include pinning But from a practical maintenance point of view, shall we just skip this for older Sphinx versions? commit 8b88430553fdaa1d7a85296a106158b5faf99a4b
Author: Hugo van Kemenade <hugovk@users.noreply.github.com>
Date: Sat Mar 11 13:32:42 2023 +0200
Skip cache-busting for old Sphinx
diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py
index 62b16f0..bbe1352 100644
--- a/python_docs_theme/__init__.py
+++ b/python_docs_theme/__init__.py
@@ -37,7 +37,7 @@ def _html_page_context(
assert isinstance(app.builder, StandaloneHTMLBuilder)
- if "css_files" in context:
+ if sphinx.version_info >= (4,) and "css_files" in context:
if "_static/pydoctheme.css" not in context["css_files"]:
raise ValueError(
"This documentation is not using `pydoctheme.css` as the stylesheet. " |
|
I think skipping is most pragmatic solution. 👍 I was also thinking about pinning, but the downside is it would prevent users from having another fixes from this release. When having similar conversation earlier, upgrading Sphinx wasn't told to be good option for already published stable releases, because of Linux distributions that provide Sphinx as a system package, if I recall correctly. |

Fix #78.
Append a
?digest=hashto the end of thepydoctheme.css, computed from the file contents, so when a new CSS file is deployed, the old one is no longer used from the browser cache.For example:
<link rel="stylesheet" type="text/css" href="_static/pydoctheme.css?digest=afc8307635b40ad4bb21df93e5fc348bcdad7f27" />This is based on how @pradyunsg's Furo theme does it:
https://github.com/pradyunsg/furo/blob/193643fdb6787501195555244f4a9e953ef544bb/src/furo/__init__.py#L149-L161
Demo
View the source of pages at https://python-docs-theme-previews--108.org.readthedocs.build/en/108/