Skip to content

Serve minified static assets and stop blocking HTML parsing - #13

Open
mamico wants to merge 2 commits into
mainfrom
minify-and-defer-static-js
Open

Serve minified static assets and stop blocking HTML parsing#13
mamico wants to merge 2 commits into
mainfrom
minify-and-defer-static-js

Conversation

@mamico

@mamico mamico commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

  • The two custom JS files served alongside chefcookie.min.js (redturtle_chefcookie.js and redturtle_chefcookie_tech.js, ~20KB/~15KB) plus styles.css were shipped unminified. Added minified counterparts (esbuild) and pointed the redturtle.chefcookiejs viewlet at them.
  • The three <script> tags injected in IHtmlHead had no async/defer, so they blocked HTML parsing. Added defer: execution order is preserved (needed since redturtle_chefcookie(.tech).js extends the chefcookie class and cookie_config.js instantiates it), and third-party tracking scripts are gated via the type="text/plain"/data-cc-src rewrite mechanism rather than script load order, so this doesn't weaken cookie-consent gating.
  • Added make minify / make check-minified plus a CI workflow (.github/workflows/minified-assets.yml) that regenerates the minified assets and diffs them against what's committed, so a source edit without a matching minified rebuild fails CI. (An mtime-based check was considered but rejected: git doesn't preserve mtimes on checkout, so it would be a no-op in CI.)

Test plan

  • node --check on both generated .min.js files
  • Verified minifier preserves the redturtlechefcookie class name and instance method names referenced by name from cookie_config.py (isAccepted, init, acceptAllScripts, etc.)
  • make check-minified passes clean on current sources; manually verified it fails when a source is changed without regenerating (tested, then reverted)
  • Manual smoke test of the cookie banner in a running Plone instance (not done in this environment)

- Add minified counterparts (redturtle_chefcookie.min.js,
  redturtle_chefcookie_tech.min.js, styles.min.css) for the assets that
  were previously served unminified, and point the viewlet at them.
- Add `defer` to the injected <script> tags so they no longer block
  page rendering. Third-party tracking scripts are still gated via the
  type="text/plain"/data-cc-src mechanism, which does not depend on
  execution order, so this is safe.
- Add `make minify`/`make check-minified` and a CI workflow that
  regenerates the minified assets and diffs them against what's
  committed, to catch a source edited without regenerating its `.min`
  counterpart (mtime comparison is not reliable in CI since git does
  not preserve mtimes on checkout).
@mamico
mamico requested a review from cekk August 5, 2026 13:20
Comment thread .github/workflows/minified-assets.yml Fixed
…ntain permissions'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.

2 participants