Frontier Software

Assets

Global resources are kept in the assets directory.

I initially didn’t get the advantage of putting CSS and JS files in the assets directory rather than the static directory and found it a little confusing that the reason is explained in Hugo Pipes which are unrelated to the | operator in template functions which are called Go Pipes.

Before discovering the advantages of the assets folder over static, I had a problem that browsers wouldn’t load upload style and script files. Filenames in the assets folder get a unique fingerprint (aka hashes) when they are changed. It also allows translation of style and JS files from other languages if desired, and minification.

{{ $mainJs := resources.Get "js/main.js" | js.Build "main.js" | minify | fingerprint }}

Note the lowercase resources.Get for a global resource in the assets directory in contrast to a page resource which would be .Resources.Get, ie upper case preceded by dot.

Asset Management

js.Build