Images: basic principles

Hello there,

My understanding is that all images should be stored under the /assets folder to be manipulated and picked with the resources.getMatch.

In theory this should make the /static folder redundant.

However, I just realised that images in the asset folder, if not referenced anywhere, are not get published.

In my case, I have some images being used in a .scss file, which are not pushed through.
Are there any best practices?

Splitting images between two folders, doesn’t sound efficient when it come to managing them.
Thnanks

No, the static folder is not redundant.
Its purpose is to push static files upon build (all files that are inside) and can be used to serve non-Hugo-specific files.

As you noticed, assets are only taken upon build when they are referenced (called).
I don’t use assets folder at all but instead, I specified assets folder to be a content folder so I got images along the content.

assetDir = "content"

In your case, you probably need to put them into a static folder. Files served inside CSS are not dynamic. They are not reprocessed during build hence they are static.

You need to understand the purpose of both folders.
Use assets for the mages used in markdown and static for other parts, like website layout.

1 Like

In addition to the explanation of @idarek: You can also store your images in a page bundle, e.g. those required by this page.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.