Meta tags:
description= Static file serving is essential for web applications that need to deliver assets like images, CSS, JavaScript, documents, or other resources. Relic provides a powerful StaticHandler that automatically handles MIME types, caching headers, security, and advanced features like cache busting.;
Headings (most frequently used words):
serving, cache, examples, further, reading, term, caching, static, files, basic, directory, single, file, control, strategies, busting, security, considerations, short, long, with, immutable, assets, api, documentation,
Text of the page (most frequently used words):
cache (33), #static (20), files (20), file (19), directory (18), the (17), final (15), with (13), for (13), busting (12), #caching (12), statichandler (12), serving (11), method (10), control (9), get (8), term (7), basic (7), and (7), serve (7), that (7), hello (7), txt (7), long (6), immutable (6), cachecontrolheader (6), from (6), like (6), true (6), buster (6), head (6), app (6), logo (6), documentation (5), assets (5), this (5), http (5), cachebustingconfig (5), handler (5), path (5), ashandler (5), maxage (5), fileinfo (5), req (5), cachecontrol (5), staticdir (5), anyof (5), html (5), body (5), svg (5), further (4), reading (4), examples (4), security (4), short (4), single (4), example (4), tail (4), pattern (4), when (4), use (4), changes (4), browsers (4), assetpath (4), urls (4), relic (4), api (3), page (3), mozilla (3), header (3), class (3), other (3), which (3), serves (3), see (3), busted (3), content (3), publiccache (3), change (3), provides (3), considerations (2), strategies (2), hot (2), reload (2), next (2), middleware (2), handling (2), need (2), useful (2), routing (2), matching (2), all (2), determine (2), within (2), automatically (2), your (2), symbolic (2), access (2), protection (2), specified (2), built (2), features (2), fetch (2), version (2), year (2), usage (2), 31536000 (2), automatic (2), mimetype (2), logourl (2), hellourl (2), await (2), never (2), 3600 (2), resources (2), _static_files (2), localhost (2), 8080 (2), static_files (2), day (2), 86400 (2), mime (2), handles (2), requests (2), reference (2), copyright, 2026, serverpod, authors, previous, edit, etags, etag, configuration, complete, you, don, but, can, spas, scenarios, always, capture, subdirectories, portion, used, without, won, know, paths, these, protections, are, applied, ensure, only, intended, safely, resolves, links, allowed, link, blocks, starting, git, env, hidden, prevents, outside, traversal, includes, hash, forcing, new, settings, durations, because, url, aggressive, returns, something, 6cb65f8d93fd9c4afe283092b9c3f74cafc04e33, generate, instantiation, generates, unique, based, hashes, configure, how, works, safe, versioning, fromstring, response, return, alt, height, img, src, href, async, respondwith, create, index, demonstrates, filesystemroot, mountprefix, config, ensures, updated, support, tell, revalidate, versioned, enable, cdn, proxy, hour, might, frequently, effective, crucial, performance, flexible, options, specific, logos, favicons, robots, well, known, individual, under, sets, duration, seconds, instructing, cdns, creates, type, detection, uses, where, captures, remaining, segments, both, standard, methods, what, code, does, essential, web, applications, deliver, images, css, javascript, documents, powerful, types, headers, advanced, pipeline, legacy, responses, context, properties, handlers, migration, shelf, world, installation, getting, started, introduction, github, twitter, career, skip, main,
Text of the page (random words):
static files relic skip to main content 1 1 0 next 1 1 0 1 0 0 api reference career twitter github introduction getting started installation hello world ️ migration from shelf reference handlers context properties routing requests responses body middleware static files hot reload pipeline legacy version 1 1 0 on this page static files static file serving is essential for web applications that need to deliver assets like images css javascript documents or other resources relic provides a powerful statichandler that automatically handles mime types caching headers security and advanced features like cache busting basic directory serving to serve static files from a directory use statichandler directory serve directory with cache app anyof method get method head basic statichandler directory staticdir cachecontrol final req final fileinfo cachecontrolheader maxage 86400 ashandler what this code does http methods anyof method get method head handles both get and head requests which is standard for static file serving path pattern basic uses a tail matching pattern where captures the remaining path segments to determine which file to serve static handler statichandler directory creates a handler that serves files from the specified directory with automatic mime type detection cache control sets a cache duration of 86400 seconds 1 day instructing browsers and cdns to cache the files this serves all files from the _static_files directory under basic urls with 1 day caching for example static_files hello txt http localhost 8080 basic hello txt static_files logo svg http localhost 8080 basic logo svg single file serving for serving individual files use statichandler file serve single file app get logo svg statichandler file file example _static_files logo svg cachecontrol final req final fileinfo cachecontrolheader maxage 3600 ashandler this is useful for specific files like logos favicons robots txt or other well known resources cache control strategies effective caching is crucial for static file performance relic provides flexible cache control options short term caching for files that might change frequently short term cache control app anyof method get method head short cache statichandler directory staticdir cachecontrol final req final fileinfo cachecontrolheader cache for 1 hour maxage 3600 enable cdn and proxy caching publiccache true ashandler long term caching with immutable assets for assets that never change like versioned files long term immutable caching app anyof method get method head long cache statichandler directory staticdir cachecontrol final req final fileinfo cachecontrolheader cache for 1 year maxage 31536000 publiccache true tell browsers never to revalidate immutable true ashandler cache busting cache busting ensures browsers fetch updated files when your assets change relic provides built in cache busting support cache busting config and usage final buster cachebustingconfig mountprefix static filesystemroot staticdir create an index page that demonstrates cache busted urls app get respondwith final _ async final hellourl await buster assetpath static hello txt final logourl await buster assetpath static logo svg final html html body h1 static files with cache busting h1 ul li a href hellourl hello txt a li li img src logourl alt logo height 64 li ul body html return response ok body body fromstring html mimetype mimetype html serve static files with automatic cache busting app anyof method get method head static statichandler directory staticdir cachecontrol final req final fileinfo cachecontrolheader safe to cache long term with versioning maxage 31536000 publiccache true immutable true cachebustingconfig buster ashandler how cache busting works configure cache busting see the cachebustingconfig instantiation cachebustingconfig generates unique urls based on file content hashes generate cache busted urls see usage of buster assetpath buster assetpath static hello txt returns something like static hello 6cb65f8d93fd9c4afe283092b9c3f74cafc04e33 txt serve with aggressive caching see cache control settings for cache busted serving use long cache durations 1 year with immutable true because the url changes when content changes when the file changes the hash changes forcing browsers to fetch the new version security considerations statichandler includes built in security features path traversal protection prevents access to files outside the specified directory hidden file protection blocks access to files starting with like env git symbolic link handling safely resolves symbolic links within the allowed directory these protections are automatically applied and ensure that your static file handler only serves files from the intended directory directory paths when serving static files from a directory always use a tail matching path pattern to capture all files and subdirectories the tail portion is used to determine the file path within the directory without it the handler won t know which file to serve for single file serving with statichandler file you don t need the tail pattern but it can be useful for spas or other routing scenarios examples further reading examples static files example complete example with cache busting api documentation statichandler class static file serving handler cachebustingconfig class cache busting configuration cachecontrolheader class cache control header handling further reading http caching mozilla documentation on http caching cache control header mozilla documentation on cache control etag header mozilla documentation on etags edit this page previous middleware next hot reload basic directory serving single file serving cache control strategies short term caching long term caching with immutable assets cache busting security considerations examples further reading examples api documentation further reading copyright 2026 serverpod authors
|