Deployment
Deploying Swap.Htmx applications to production.
Overview
Since Swap.Htmx applications are standard ASP.NET Core applications, you can deploy them anywhere .NET runs.
- Azure App Service
- AWS Elastic Beanstalk
- Docker / Kubernetes
- Linux (Nginx/Kestrel)
- Windows (IIS)
There are no special build steps (like npm build) required for the specialized Swap features.
Client Assets (LibMan)
The only strict requirement is ensuring your static assets (HTMX, Swap.Client.js, CSS) are available.
If you used the LibMan setup (recommended in templates), ensure your build pipeline restores libraries:
# GitHub Actions Example
- name: Restore Local Tools
run: dotnet tool restore
- name: Restore Client Libs
run: libman restore
Alternatively, sticking to CDN references for HTMX avoids this step entirely.
Performance Tuning
1. Compression
Swap.Htmx templates include Brotli/Gzip compression by default. Ensure this is enabled in Program.cs for production.
builder.Services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
});
2. Output Caching
Because Swap.Htmx relies on dynamic HTML generation (often user-specific), be careful with standard Response Caching.
Prefer Data Caching (IMemoryCache/IDistributedCache) over Output Caching for authorized pages.
For public pages (marketing, blog), standard Output Caching works as expected.
Docker Support
The standard Microsoft .NET Dockerfile works out of the box.
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore
# Install tool locally if needed, or rely on committed libs
RUN dotnet publish -c Release -o /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]