Skip to content

Commit ae24463

Browse files
committed
WIP links, small changes
1 parent a5012c7 commit ae24463

1 file changed

Lines changed: 13 additions & 39 deletions

File tree

src/content/docs/docs/guides/examples/handling-assets.mdx

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Assets are static resources that your application use. In FSD, the placement of
1010

1111
<Aside type="caution">
1212

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

1515
</Aside>
1616

17-
## Global Assets
17+
## Global Assets \{#global-assets}
1818

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

2121
<FileTree>
2222
- app/
@@ -26,7 +26,7 @@ Global assets include things like global stylesheets (like css reset), fonts and
2626
- main.ts
2727
</FileTree>
2828

29-
## Slice-specific Assets
29+
## Slice-specific Assets \{#slice-specific-assets}
3030

3131
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:
3232

@@ -54,7 +54,7 @@ If your UI has a lot of static assets like images, you can create a subfolder in
5454
</FileTree>
5555

5656

57-
## Non-UI Assets
57+
## Non-UI Assets \{#non-ui-assets}
5858

5959
There are cases when asset is not part of UI, but a crucial part of business logic. Consider this example:
6060

@@ -69,46 +69,20 @@ There are cases when asset is not part of UI, but a crucial part of business log
6969

7070
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.
7171

72-
## Public Folder
72+
## Public Folder \{#public}
7373

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

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

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-
<img src="/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.
103-
104-
## Summary
78+
## Summary \{#summary}
10579

10680
| Asset Type | Location |
10781
|------------|----------|
108-
| Reusable icons, images | `shared/ui/` (as components) |
109-
| Global styles | `shared/styles/` |
110-
| Fonts | `shared/fonts/` or `public/` |
82+
| Reusable icons and images | `shared/ui/` |
83+
| Global styles | `app/styles/` |
84+
| Fonts | `app/fonts/` or `public/` |
11185
| Slice-specific assets | Inside the slice (e.g., `pages/home/ui/`) |
112-
| Static files, favicon | `public/` at project root |
86+
| Static files, favicon | `public/` or `app/public` |
11387

11488
Follow the FSD principle: place assets where they are used, and move them to `shared` when there's an actual need for reuse across slices.

0 commit comments

Comments
 (0)