Improve documentation for add_js_file() and add_css_file()#14322
Open
dhruvildarji wants to merge 1 commit intosphinx-doc:masterfrom
Open
Improve documentation for add_js_file() and add_css_file()#14322dhruvildarji wants to merge 1 commit intosphinx-doc:masterfrom
dhruvildarji wants to merge 1 commit intosphinx-doc:masterfrom
Conversation
Address documentation gaps identified in sphinx-doc#12223: - Update examples to show CRC32 checksum query parameters (?v=...) that are appended to local asset URIs since Sphinx 7.1 - Add "versionchanged:: 7.1" notes documenting the checksum feature - Add note explaining how JS/CSS files can be copied to _static (via add_static_dir for extensions, html_static_path for site authors) - Add tip mentioning that site authors can use html_js_files and html_css_files config values with html_static_path as an alternative to writing an extension - Add note about overriding extension files via html_static_path, with a caveat linking to sphinx-doc#12096 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gastmaier
suggested changes
Feb 27, 2026
| @@ -1461,14 +1461,38 @@ def add_js_file( | |||
| Example:: | |||
There was a problem hiding this comment.
I think the overall description could be simpler.
add_js_file always adds the .js file to the .html, and suffixes it with the checksum if it is available.
For example, app.config.html_static_path.append + add_js_file at 'builder_inited' will generate the checksum, while add_js_file at 'builder_inited' and copy_asset at 'build_finished' will not suffix with the checksum, because the generation step already happened.
For both, the .js script tag are added to the html page.
See for reference analogdevicesinc/doctools@42be7a6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #12223.
This PR improves the documentation for
Sphinx.add_js_file()andSphinx.add_css_file()by addressing all five items raised in the issue:Updated examples with CRC32 checksums — Example output comments now show the
?v=a1b2c3d4query parameter that Sphinx appends to local asset URIs since version 7.1.Added
versionchanged:: 7.1notes — Both methods now document that a CRC32 checksum is appended as a query parameter to local asset URIs for cache-busting purposes.Hint on copying files to
_static— Added a note explaining that extension developers should useadd_static_dir()to register directories, while site authors can usehtml_static_path.Mention of
html_js_files/html_css_filesfor site authors — Added a tip suggesting that site authors may find it easier to use these config values rather than writing an extension.Override note with Regression: CSS file added by extension cannot be overridden by users anymore #12096 caveat — Added a note that files registered by extensions can be overridden by placing a file with the same name in
html_static_path, with a caveat linking to Regression: CSS file added by extension cannot be overridden by users anymore #12096.Test plan