-
Notifications
You must be signed in to change notification settings - Fork 0
Static Assets and CDN Paths
Serve local files with ASP.NET Core static-file middleware before Imp:
app.UseStaticFiles();
app.UseImp(/* ... */);In an Imp template, prefix an attribute name with Cdn.:
<link rel="stylesheet" Cdn.href="/styles/site.css" />
<script Cdn.src="/scripts/site.js"></script>The compiler removes Cdn. and transforms the value. With:
.CdnPrefix("https://cdn.example.com")the rendered attributes use https://cdn.example.com/styles/site.css and the equivalent script URL.
The prefix is concatenated literally. Choose trailing/leading slashes consistently and test the result.
OnBuildCdnPath receives every CDN-aware path after prefixing:
var version = typeof(Program).Assembly.GetName().Version;
.OnBuildCdnPath(path => $"{path}?v={version}")Use it for cache versions, content hashes, tenant paths, or another deterministic rewrite. It is called during template compilation, so values are effectively fixed for the process lifetime of that compiled page type.
The Todo sample deliberately uses an empty prefix plus a version callback. Assets stay local while demonstrating the same template syntax.
- Configure CDN origins; do not derive them directly from request input.
- Use HTTPS.
- Apply an appropriate Content Security Policy.
- Preserve existing query strings when appending versions.
- URL-encode dynamic URL components.
- Set long cache lifetimes only for versioned/immutable assets.
- Remember that
Cdn.*rewrites template-authored attributes, not URLs written by dynamic methods.
Because UseStaticFiles runs first, successful file requests never reach Imp. Missing file requests continue and may become an Imp 404 page. This is expected pipeline behavior.
Imp is MIT licensed. See the source and Todo sample on GitHub.
Imp
Templates
Application integration
- Forms and antiforgery
- Dependency injection
- Authentication and secure pages
- Static assets and CDN paths
- Configuration reference
Help and reference