You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/docs/guides/examples/handling-assets.mdx
+13-39Lines changed: 13 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ Assets are static resources that your application use. In FSD, the placement of
10
10
11
11
<Asidetype="caution">
12
12
13
-
It's a common practice to implement a custom `assets` segment (http://localhost:4321/docs/reference/slices-segments/#segments), but just like the code, this creates an issue of desegmentation (http://localhost:4321/docs/guides/issues/desegmented/) and should be generally avoided.
13
+
It's a common practice to implement a [custom `assets` segment](/docs/reference/slices-segments/#segments), but just like the code, this creates an issue of [desegmentation](/docs/guides/issues/desegmented/) and should be generally avoided.
14
14
15
15
</Aside>
16
16
17
-
## Global Assets
17
+
## Global Assets\{#global-assets}
18
18
19
-
Global assets include things like global stylesheets (like css reset), fonts and so on. `app` is the appropriate layer for those kind of files, as they are not reused by any other component, and will be used by the application entrypoint.
19
+
Global assets include things like global stylesheets (like css reset), fonts and so on. `app` is the appropriate layer for those kind of files, as they are not used by any other component except for the application entrypoint.
20
20
21
21
<FileTree>
22
22
- app/
@@ -26,7 +26,7 @@ Global assets include things like global stylesheets (like css reset), fonts and
26
26
- main.ts
27
27
</FileTree>
28
28
29
-
## Slice-specific Assets
29
+
## Slice-specific Assets\{#slice-specific-assets}
30
30
31
31
When an asset is only used by one page, widget, or feature, keep it inside that slice. This maintains encapsulation and makes it clear where the asset belongs:
32
32
@@ -54,7 +54,7 @@ If your UI has a lot of static assets like images, you can create a subfolder in
54
54
</FileTree>
55
55
56
56
57
-
## Non-UI Assets
57
+
## Non-UI Assets\{#non-ui-assets}
58
58
59
59
There are cases when asset is not part of UI, but a crucial part of business logic. Consider this example:
60
60
@@ -69,46 +69,20 @@ There are cases when asset is not part of UI, but a crucial part of business log
69
69
70
70
In this example, while `invoicing-template.pdf` is a static asset, it is tightly coupled with the core business logic in `create-invoice.ts`. In cases like that, it is preferrable to place `invoice-template.pdf` in the `model` segment to maintain high cohesion.
71
71
72
-
## Public Folder
72
+
## Public Folder\{#public}
73
73
74
-
Most bundlers and frameworks provide a `public/` folder at the root of your project. Files here are served as-is without processing. Use this folder for:
74
+
Most bundlers and frameworks provide a `public` folder at the root of your project. Files here are served as-is without processing.
75
75
76
-
-**favicon.ico** and other browser-required files
77
-
-**robots.txt** and SEO-related files
78
-
-**Static files** that don't need to be processed by your bundler
79
-
-**Large assets** that would unnecessarily increase your bundle size
76
+
Some build tools like [Vite](https://vite.dev/config/shared-options#publicdir) allows public folder to be changed, while others like [Astro](https://docs.astro.build/en/basics/project-structure/#public) don't have this option. If your build tool doesn't support this change, it is ok to leave it as it is, as the `public` folder is not part of the FSD structure and won't have name collisions with it.
80
77
81
-
The `public/` folder is not part of the FSD structure — it's external to it. Reference these assets with absolute paths from your site root:
82
-
83
-
```tsx
84
-
<imgsrc="/images/hero.jpg"alt="Hero" />
85
-
```
86
-
87
-
## Stylesheets
88
-
89
-
Global styles belong in `shared/styles`. For framework-specific approaches:
90
-
91
-
-**CSS Modules** — can be placed alongside components (`Button.module.css` next to `Button.tsx`)
92
-
-**Global CSS** — place in `shared/styles` and import in your app entry point
93
-
-**CSS-in-JS** — usually doesn't need separate asset files
94
-
95
-
96
-
## Framework-specific Considerations
97
-
98
-
Some frameworks have specific requirements for asset handling:
99
-
100
-
-**Next.js** — uses `next/image` for optimized images, and has a `public/` folder at the root. See the [Next.js integration guide](/docs/guides/tech/with-nextjs) for FSD-specific routing setup.
101
-
-**Astro** — has its own asset handling with Image component. See the [Astro integration guide](/docs/guides/tech/with-astro).
102
-
-**Vite** — imports assets as URLs by default, works well with the patterns described above.
0 commit comments