3. Paths and assets
- Relative paths (
assets/img.jpg,../assets/img.jpg,./assets/img.jpg) are resolved against the section file and, if it doesn’t exist there, against the package root. They are fixed insrc,srcset,poster,href(files, not pages),style="...url()"and in<style>blocks, also inside<template>. The same goes for the most common lazy-loading attributes:srcset,data-src,data-srcset,data-bg,data-background,data-posterand<video poster>. Only the value that resolves to an existing package file is rewritten; external URLs, absolute paths and nonexistent files are left as they are. Attributes with custom names (for exampledata-near-src) aren’t touched: the JS that reads them would receive the relative path and get a 404. The same applies to the value ofrichtextfields (including the one translated ini18n/<language>.json): when rendering, their relativesrc,srcset,data-src,data-srcset,posteranddata-posterthat resolve to a package file are changed to the package URL, so an<img src="img/x.svg">inside a richtext works withoutdata-srcor JS. Only what exists in the package is rewritten, and the result goes in the section cache. - The
url()entries in the CSS work unchanged because they are served from their folder. If they point to a nonexistent file, the validator warns you. - Load order: if
index.htmlexists, the order of its<head>is respected, including external CSS and JS (Google Fonts, GSAP from a CDN…),preconnecttags, inline<style>and inline<script>. Then the rest of the files incss/andjs/are loaded in natural alphabetical order. To control the order completely, usestylesandscriptsinbos.json.- Inline
<script>: by default they are merged into.bos/inline.jsand loaded deferred, wrapped in a function (they don’t run before the first paint). If you need one to run earlier (e.g. putting a class on<html>to avoid a flicker), mark it withdata-bos-nodelay: BuilderOS prints it inline, not deferred and not wrapped where you put it — in the<head>ofindex.htmlit comes out in the page’s<head>(before the package stylesheets); in the<body>, at the end of the page — and “Delay JavaScript” (Performance) doesn’t delay it either. It must be small and not contain</script>; if it does, it stays in the deferred file. <link rel="preload">in the<head>ofindex.html(as="font",image,styleorscript; package path or URL): BuilderOS prints it in the<head>of the pages that load the package, always (it doesn’t depend on any Performance option). Fonts come out withtype="font/woff2"(according to the extension) andcrossorigin, needed so the browser doesn’t request them twice. If “Preload the package’s woff2 fonts” picks the same URL, it isn’t repeated. A path that doesn’t exist in the package gives a warning on validation.
- Inline
- Conditional loading: by default, the CSS and JS are only loaded on pages that use some section of the package. It can be changed in Settings or with
"loading": "global"inbos.json. - In the editor: the package’s CSS is applied inside the canvas in a scoped way, so a
body {}or a reset doesn’t break the WordPress interface. The package’s JS is not loaded in the editor unless you ask for it with"editor": { "scripts": true }.
JS that works in the editor and on the frontend
Initialize per section with BuilderOS.ready. The editor calls it again every time it repaints a block, so your code must tolerate running more than once:
BuilderOS.ready(function (block) {
// block = elemento raíz de la sección (.bos-block)
block.querySelectorAll('.slider').forEach(initSlider);
});For interactive pieces with options the client can change (accordion, tabs, carousel, counter, before/after) use the components (data-bos-component) instead of coding them, or register your own with BuilderOS.component('nombre', function (el, opciones) { …; return { destroy() {} }; }): see the “Interactive components” chapter.