CSS
css/asset-url
In a bundled project, url() to images and fonts is a relative path or alias the bundler resolves, not a hard-coded root or public/ path.
drobnastatycznefe-css-architecture
Dlaczego
A relative url() makes the file part of the build: the bundler checks that it exists, gives it a content hash (so a changed image is never served stale from cache) and writes the final URL, including the base path when the site lives under a sub-path. A root path such as /images/hero.jpg points at a public file instead: it is copied as-is without a hash, and in a framework that does not rewrite it (Next.js basePath, for example) it breaks when the base path changes.
Poprawka
Keep images and fonts next to the source (src/assets/…) and reference them relatively (url('../assets/hero.jpg')) or through the project's alias (@/assets/…, ~/assets/…). Keep public/ for files that must keep their exact name and are not referenced from code (robots.txt, favicon.ico). In component code, import the file or use the framework's helper (see js/asset-import).
Przykłady
/* bad */
.hero { background-image: url('/images/hero.jpg'); }
/* good */
.hero { background-image: url('../assets/images/hero.jpg'); }Źródła
Fakty
- Identyfikator
css/asset-url- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
cssscsslesshtmlvuesvelteastro- Tylko w projektach z
vitewebpacknextnuxtangularastrosveltekit- Uczy jej skill
fe-css-architectureCSS architecture and tokens- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain css/asset-url