fix(static-assets): also cache-bust raw /static/ refs (fonts CSS, store JS)
All checks were successful
All checks were successful
The initial codemod only converted url_for('*_static', path='*.js'|'*.css')
patterns and missed 19 raw /static/... references — most importantly the
shared/fonts/inter.css link in all four base.html files, plus a handful
of <script src="/static/modules/..."> tags in marketplace/billing/orders
templates and the storefront login/register/forgot/reset pages.
Result: deploys now flip ?v=<sha> on every JS/CSS asset that reaches the
browser, not just the ones loaded via url_for().
FE-024 rule extended to flag src="/static/...*.(js|css)" patterns too.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -937,7 +937,7 @@ frontend_component_rules:
|
||||
- "{% from 'shared/macros/shop/trust-badges.html' import"
|
||||
|
||||
- id: "FE-024"
|
||||
name: "Use static_v() for JS/CSS, not raw url_for()"
|
||||
name: "Use static_v() for JS/CSS, not raw url_for() or /static/ paths"
|
||||
severity: "warning"
|
||||
description: |
|
||||
Static .js and .css URLs must use the cache-busting `static_v()` helper
|
||||
@@ -948,17 +948,20 @@ frontend_component_rules:
|
||||
WRONG (browser keeps cached file after deploy):
|
||||
<script src="{{ url_for('foo_static', path='admin/js/app.js') }}"></script>
|
||||
<link href="{{ url_for('foo_static', path='admin/css/site.css') }}" rel="stylesheet">
|
||||
<link href="/static/shared/fonts/inter.css" rel="stylesheet">
|
||||
|
||||
RIGHT:
|
||||
<script src="{{ static_v(request, 'foo_static', path='admin/js/app.js') }}"></script>
|
||||
<link href="{{ static_v(request, 'foo_static', path='admin/css/site.css') }}" rel="stylesheet">
|
||||
<link href="{{ static_v(request, 'static', path='shared/fonts/inter.css') }}" rel="stylesheet">
|
||||
|
||||
Images, fonts, and JSON locale files are intentionally out of scope —
|
||||
keep using `url_for()` for those.
|
||||
Images, fonts (other than .css), and JSON locale files are intentionally
|
||||
out of scope — keep using `url_for()` for those.
|
||||
pattern:
|
||||
file_pattern: "app/**/templates/**/*.html"
|
||||
anti_patterns:
|
||||
- "url_for\\(\\s*['\"]\\w+_static['\"]\\s*,\\s*path=['\"][^'\"]+\\.(?:js|css)['\"]"
|
||||
- "(?:src|href)=['\"]/static/[^'\"]+\\.(?:js|css)['\"]"
|
||||
exceptions:
|
||||
- "base.html"
|
||||
- "partials/"
|
||||
|
||||
Reference in New Issue
Block a user