Skip to content

Improve documentation for add_js_file() and add_css_file()#14322

Open
dhruvildarji wants to merge 1 commit intosphinx-doc:masterfrom
dhruvildarji:docs/add-js-css-file-docs
Open

Improve documentation for add_js_file() and add_css_file()#14322
dhruvildarji wants to merge 1 commit intosphinx-doc:masterfrom
dhruvildarji:docs/add-js-css-file-docs

Conversation

@dhruvildarji
Copy link

Summary

Closes #12223.

This PR improves the documentation for Sphinx.add_js_file() and Sphinx.add_css_file() by addressing all five items raised in the issue:

  1. Updated examples with CRC32 checksums — Example output comments now show the ?v=a1b2c3d4 query parameter that Sphinx appends to local asset URIs since version 7.1.

  2. Added versionchanged:: 7.1 notes — Both methods now document that a CRC32 checksum is appended as a query parameter to local asset URIs for cache-busting purposes.

  3. Hint on copying files to _static — Added a note explaining that extension developers should use add_static_dir() to register directories, while site authors can use html_static_path.

  4. Mention of html_js_files/html_css_files for site authors — Added a tip suggesting that site authors may find it easier to use these config values rather than writing an extension.

  5. 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

  • Documentation-only change, no functional code modified
  • Verify the reStructuredText renders correctly in a local Sphinx build

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>
@@ -1461,14 +1461,38 @@ def add_js_file(
Example::

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incomplete documentation for add_js_file() and add_css_file()

2 participants