aicoded.dev

Scripts, styles and images

A page's script is index.ts and its styles index.css, next to its template. aicoded generate builds them with esbuild, which is built into aicoded, copies the page's images, and embeds everything in the app, so there is no Node.js, npm or node_modules and no build step of your own.

The files

pages/
  index.html
  index.css          styles of the layout, loaded on every page inside it
  home/
    index.html
    index.ts         the home page's script
    logo.svg         an image the template shows
assets/
  team.png           an image any page shows as /assets/team.png

Loading them

<ssr:assets/> writes the <link rel="stylesheet"> and <script defer> tags of its own page and of every page shown inside it, each once. Put it in the <head> of the top layout, usually pages/index.html:

<head>
<meta charset="utf-8">
<ssr:access role="*"/>
<title>People</title>
<ssr:assets/>
</head>

Images

An <img src> that names a file next to the template, such as src="logo.svg", or src="/assets/<file>" in the app's assets/ folder, is copied into the app with a hash in its name, and the tag points at the copy.

How they are served

The build writes to pages/assets_gen/, and the generated pages/assets_gen.go embeds that folder in the app binary. Both are committed, like every generated file. The app serves them at /_aicoded/assets/<path>:

aicoded dev builds them again when a file changes. To build them yourself, run aicoded generate.

The Content-Security-Policy

Every page carries this policy, which the app sets and a hook cannot change:

default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'

No inline script, inline style or code from another site runs, and no other site can frame the page. That is why the generator refuses <script> bodies, <style>, style and on… attributes: they would not run anyway.

See also

Markdown · Source on GitHub · framework f46741f