[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"docs:adr\u002F0009-resources-in-batches":3},{"versions":4,"version":29,"nav":32,"path":127,"page":129},[5,10,13,17,20,23,26],{"name":6,"label":7,"prefix":8,"channel":9},"1.3","1.3.0 (latest)","","latest",{"name":11,"label":12,"prefix":11,"channel":11},"next","next (main)",{"name":14,"label":15,"prefix":14,"channel":16},"1.2","1.2.1","old",{"name":18,"label":19,"prefix":18,"channel":16},"1.1","1.1.1",{"name":21,"label":22,"prefix":21,"channel":16},"1.0","1.0.0",{"name":24,"label":25,"prefix":24,"channel":16},"0.2","0.2.0",{"name":27,"label":28,"prefix":27,"channel":16},"0.1","0.1.0",{"name":6,"label":7,"prefix":8,"channel":9,"base":30,"ref":31},"\u002Fdocs","v1.3.0",[33,37,40,43,46,49,52,55,58,61,64,68,71,74,77,80,83,86,89,93,96,99,102,105,108,111,114,117,120,123,126],{"slug":34,"title":35,"group":36},"index","Overview","Guide",{"slug":38,"title":39,"group":36},"getting-started","Getting started",{"slug":41,"title":42,"group":36},"php","PHP API",{"slug":44,"title":45,"group":36},"laravel","Laravel",{"slug":47,"title":48,"group":36},"resources","Resources",{"slug":50,"title":51,"group":36},"deployment","Deployment",{"slug":53,"title":54,"group":36},"troubleshooting","Troubleshooting",{"slug":56,"title":57,"group":36},"from-wkhtmltopdf","Coming from wkhtmltopdf",{"slug":59,"title":60,"group":36},"stability","Stability and upgrades",{"slug":62,"title":63,"group":36},"ai-assistants","Docs for AI assistants",{"slug":65,"title":66,"group":67},"css","CSS reference","Reference",{"slug":69,"title":70,"group":67},"paged-media","Paged media",{"slug":72,"title":73,"group":67},"fonts","Fonts",{"slug":75,"title":76,"group":67},"extensions","Extensions",{"slug":78,"title":79,"group":67},"compatibility","Compatibility",{"slug":81,"title":82,"group":67},"pdf","The PDF",{"slug":84,"title":85,"group":67},"cli","Command line",{"slug":87,"title":88,"group":67},"rust","Rust library",{"slug":90,"title":91,"group":92},"ffi","C library (experimental)","Internals",{"slug":94,"title":95,"group":92},"protocol","Worker protocol",{"slug":97,"title":98,"group":92},"releasing","Releasing",{"slug":100,"title":101,"group":92},"adr","Architecture decisions",{"slug":103,"title":104,"group":92,"parent":101},"adr\u002F0001-record-architecture-decisions","1. Record architecture decisions",{"slug":106,"title":107,"group":92,"parent":101},"adr\u002F0002-rust-and-fragmentation-in-layout","2. Rust core with fragmentation inside layout",{"slug":109,"title":110,"group":92,"parent":101},"adr\u002F0003-css-parsing-and-own-selector-matching","3. lightningcss for parsing, own selector matching and cascade",{"slug":112,"title":113,"group":92,"parent":101},"adr\u002F0004-extensions-only-where-css-has-no-way","4. Extensions only where CSS has no way",{"slug":115,"title":116,"group":92,"parent":101},"adr\u002F0005-public-api-and-deprecations","5. Public API, semantic versioning and deprecations",{"slug":118,"title":119,"group":92,"parent":101},"adr\u002F0006-pages-that-grow-with-their-content","6. Pages that grow with their content",{"slug":121,"title":122,"group":92,"parent":101},"adr\u002F0007-layers-for-screen-and-print","7. Layers for screen and print, and form fields as an option",{"slug":124,"title":125,"group":92,"parent":101},"adr\u002F0008-c-library-experimental","8. An experimental C library beside the worker",{"slug":127,"title":128,"group":92,"parent":101},"adr\u002F0009-resources-in-batches","9. Resources in batches, fetching stays with the caller",{"title":128,"seoTitle":130,"seoDescription":131,"html":132,"headings":133,"editUrl":144,"sourceUrl":145,"markdownUrl":146,"prev":147},"Architecture decisions: 9. Resources in batches, fetching stays with the caller · Fagus docs","Fagus loads nothing on its own. A resource is a data: URL, data handed over, a file inside the root, or what the caller's resolver answers (in Rust a ResourceLoader, in the worker protocol the answer r to the question …","\u003Ch1 id=\"9-resources-in-batches-fetching-stays-with-the-caller\">9. Resources in batches, fetching stays with the caller\u003C\u002Fh1>\n\u003Cul>\n\u003Cli>Status: accepted\u003C\u002Fli>\n\u003Cli>Date: 2026-11-25\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2 id=\"context\">Context\u003Ca class=\"f-doc-anchor\" href=\"#context\" aria-label=\"Link to this section\">#\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>Fagus loads nothing on its own. A resource is a \u003Ccode>data:\u003C\u002Fcode> URL, data handed over, a file inside the\nroot, or what the caller's resolver answers (in Rust a \u003Ccode>ResourceLoader\u003C\u002Fcode>, in the worker protocol\nthe answer \u003Ccode>r\u003C\u002Fcode> to the question \u003Ccode>?\u003C\u002Fcode>). The engine asked for one URL, waited, and asked for the\nnext. For a resolver that reads from a database or a disk that is fine. For one that fetches\nfrom the network it adds the waiting up: a catalog with 50 product photos on a CDN that answers\nin 20 ms waits a second, and one with 500 waits ten, while the same requests sent together are\ndone in the time of the slowest. A browser loads them side by side.\u003C\u002Fp>\n\u003Cp>Two ways lead to the same speed. The engine could fetch itself, with an HTTP client, an\nallowlist and a pool of connections. Or the engine could say earlier what it needs, and the\ncaller, who fetches already, fetches it concurrently.\u003C\u002Fp>\n\u003Cp>Against the first:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>The engine without network access is a property users rely on and the docs promise\n(\u003Ca href=\"\u002Fdocs\u002Fresources\">resources.md\u003C\u002Fa>). On Linux the worker gives the network up for good (Landlock,\nseccomp), so no document, however hostile, makes it open a connection.\u003C\u002Fli>\n\u003Cli>Fetching for a document that may come from user input is where server-side request forgery\nhappens. What may be fetched (which hosts, which credentials, through which proxy, with which\ntimeout, how large) differs with every application, and each of those would become an option\nof Fagus, with its defaults and its mistakes to answer for.\u003C\u002Fli>\n\u003Cli>An HTTP client with TLS in the binary is a large dependency with a steady flow of security\nfixes, for something PHP and Laravel bring along.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>The engine does know most of its resources before it uses them: the \u003Ccode>&lt;link&gt;\u003C\u002Fcode>ed style sheets\nafter parsing, the fonts once the style sheets are read, the images once the styles are computed.\nOnly a few show while others are read.\u003C\u002Fp>\n\u003Ch2 id=\"decision\">Decision\u003Ca class=\"f-doc-anchor\" href=\"#decision\" aria-label=\"Link to this section\">#\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Cstrong>The engine asks for resources in batches.\u003C\u002Fstrong> \u003Ccode>ResourceLoader\u003C\u002Fcode> gets \u003Ccode>load_many(&amp;[&amp;str])\u003C\u002Fcode>, with\na default that calls \u003Ccode>load\u003C\u002Fcode> for one after the other. A render asks with it three times: for the\nlinked style sheets, for the first font file of each \u003Ccode>@font-face\u003C\u002Fcode> rule, and for the images, at\nmost 64 URLs at a time.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>A batch asks for nothing that would not be asked for anyway\u003C\u002Fstrong>, in the order it would be asked\nfor: no candidates of a \u003Ccode>srcset\u003C\u002Fcode> that are not chosen, no later sources of a font, nothing behind\na \u003Ccode>local()\u003C\u002Fcode> that is found. The engine keeps the answers by URL and then loads as before, one\nresource after the other, from what it has. So the PDF is the same bytes whether a loader\nanswers in batches, one by one, or the data was handed over, and a loader without \u003Ccode>load_many\u003C\u002Fcode>\nsees what it saw before.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>The worker protocol stays protocol 1.\u003C\u002Fstrong> A caller that can answer many at once says \u003Ccode>askMany\u003C\u002Fcode>\nin \u003Ccode>R\u003C\u002Fcode>; the worker then asks with \u003Ccode>Q\u003C\u002Fcode> (\u003Ccode>urls\u003C\u002Fcode>) and reads \u003Ccode>q\u003C\u002Fcode> (\u003Ccode>found\u003C\u002Fcode> for each, and the data of\nthose found). Both sides ignore what they do not know, so every pair of old and new worker and\ncaller works without a check of versions: an old worker ignores \u003Ccode>askMany\u003C\u002Fcode> and asks with \u003Ccode>?\u003C\u002Fcode>, a\nnew one never sends \u003Ccode>Q\u003C\u002Fcode> to a caller that did not ask for it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>PHP gets \u003Ccode>resolveMany()\u003C\u002Fcode>\u003C\u002Fstrong>, a callback from a list of URLs to data by URL, beside\n\u003Ccode>resolver()\u003C\u002Fcode>; the one called last is asked. The package sends \u003Ccode>askMany\u003C\u002Fcode> whenever a resolver is\nset, so a \u003Ccode>resolver()\u003C\u002Fcode> saves the round trips too.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Fetching stays with the caller.\u003C\u002Fstrong> There is no HTTP client in the engine or in the PHP\npackage, and no network access. The documentation has callbacks to copy: an allowlist of hosts,\n\u003Ccode>Http::pool()\u003C\u002Fcode>, \u003Ccode>curl_multi\u003C\u002Fcode>.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>A cache is a hook, not a store.\u003C\u002Fstrong> \u003Ccode>cache()\u003C\u002Fcode> takes a PSR-16 cache of the application and puts\nit in front of the resolver. The package depends on \u003Ccode>psr\u002Fsimple-cache\u003C\u002Fcode> only as a suggestion.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>Left for later: batches for the levels of \u003Ccode>@import\u003C\u002Fcode>, for the sprites and images of inline SVG,\nand for the documents of \u003Ccode>&lt;iframe&gt;\u003C\u002Fcode>s, which are asked for one by one as before.\u003C\u002Fp>\n\u003Ch2 id=\"consequences\">Consequences\u003Ca class=\"f-doc-anchor\" href=\"#consequences\" aria-label=\"Link to this section\">#\u003C\u002Fa>\u003C\u002Fh2>\n\u003Cp>A document with many remote images renders in about the time of its slowest image, if the\ncallback fetches concurrently; with \u003Ccode>resolver()\u003C\u002Fcode> nothing changes but the number of messages.\nThe rules for what is fetched stay in the application, where its hosts and secrets are, and the\nsandbox of the worker stays as tight as it was.\u003C\u002Fp>\n\u003Cp>A callback to copy is easier to get wrong than a class to call. The recipes say what each line\nis for, and the allowlist is the first of them. If the same mistakes keep being made, a package\nof its own with a checked fetcher is the answer, not a client in this one.\u003C\u002Fp>\n\u003Cp>A batch is in memory at once: in the caller, in one message, and in the worker before the\nmemory budget is charged. Sixty-four URLs a batch bound that, and the budget and the time limit\nare looked at after each.\u003C\u002Fp>\n\u003Cp>The order in which a resolver is asked changed in one place: a later source of a font is asked\nfor after the first sources of all rules, not between them.\u003C\u002Fp>\n",[134,138,141],{"id":135,"text":136,"level":137},"context","Context",2,{"id":139,"text":140,"level":137},"decision","Decision",{"id":142,"text":143,"level":137},"consequences","Consequences","https:\u002F\u002Fgithub.com\u002Fnforst\u002Ffagus\u002Fedit\u002Fmain\u002Fdocs\u002Fadr\u002F0009-resources-in-batches.md","https:\u002F\u002Fgithub.com\u002Fnforst\u002Ffagus\u002Fblob\u002Fv1.3.0\u002Fdocs\u002Fadr\u002F0009-resources-in-batches.md","\u002Fdocs\u002Fadr\u002F0009-resources-in-batches.md",{"slug":124,"title":125}]