sercrod

Config

Sercrod has a small set of runtime options that you can override through window.__Sercrod.config before loading sercrod.js. This page lists those options and their defaults.

Global override hook

To change settings, define window.__Sercrod.config before the script tag that loads sercrod.js. Only the fields you specify are overridden. Others keep their defaults.

<script>
window.__Sercrod = window.__Sercrod || {};
window.__Sercrod.config = {
	delimiters: { start: "%", end: "%" },
	include: {
		warn_on_element: true,
		remove_element_if_empty: false,
		max_depth: 16
	},
	cleanup: {
		directives: null,
		handlers: null
	},
	events: {
		prefix: "@"
	}
};
</script>
<script src="/sercrod.js"></script>

You can set only the parts you need. For example, to change the event prefix but nothing else, you can provide just events.prefix.

Delimiters

Interpolation uses delimiters around a key, such as %name%.

<script>
window.__Sercrod = window.__Sercrod || {};
window.__Sercrod.config = {
	delimiters: { start: "{{", end: "}}" }
};
</script>

This would treat {{name}} as an interpolation instead of %name%.

Include options

These options control the behavior of the *include family of directives when they pull in external fragments.

<script>
window.__Sercrod = window.__Sercrod || {};
window.__Sercrod.config = {
	include: {
		warn_on_element: false,
		remove_element_if_empty: true,
		max_depth: 8
	}
};
</script>

Cleanup options

After Sercrod has expanded directives and bound events, you may want to remove directive attributes and event attributes from the DOM. This is common in SSG or SSR builds.

<script>
window.__Sercrod = window.__Sercrod || {};
window.__Sercrod.config = {
	cleanup: {
		directives: true,
		handlers: true
	}
};
</script>

The official Playwright based renderer uses these options during the build step so that the final static HTML no longer contains Sercrod specific attributes.

Event options

These options control how Sercrod interprets event attributes and which events are treated as non mutating.

<script>
window.__Sercrod = window.__Sercrod || {};
window.__Sercrod.config = {
	events: {
		prefix: "ne-",
		non_mutating: ["mouseover","mousemove","scroll"]
	}
};
</script>

In most cases you do not need to override non_mutating. It is exposed so that you can tune performance for special cases.

Defaults at a glance

For reference, the built in defaults are equivalent to this structure inside the runtime:

delimiters: {
	start: "%",
	end: "%"
},
include: {
	warn_on_element: true,
	remove_element_if_empty: false,
	max_depth: 16,
	terminator: null
},
cleanup: {
	directives: null,
	handlers: null,
	terminator: null
},
events: {
	prefix: "@",
	non_mutating: [
		"mouseover","mouseenter","mousemove","mouseout","mouseleave","mousedown",
		"pointerover","pointerenter","pointermove","pointerout","pointerleave",
		"pointerrawupdate","pointerdown",
		"wheel","scroll","touchmove","touchstart",
		"dragstart","drag","dragenter","dragover","dragleave","dragend",
		"resize","timeupdate",
		"selectionchange"
	],
	terminator: null
}

Internal terminator fields are reserved for future use and should be left as null.