As a follow-up on the presentation I did at CloudBrew about Azure Static Web Apps I want to write a series of blog posts.
- Part I - Using the VS Code Extension
- Part II - Using the Astro Static Site Generator
- Part III – Deploying to multiple environments
- Part IV – Password protect your environments
- Part V – Traffic splitting
- Part VI – Authentication using pre-configured providers
- Part VII – Application configuration using staticwebapp.config.json
- Part VIII – API Configuration
- Part IX(this post) – Injecting snippets
Before I continue with authentication and authorization, I want to spend one last post on configuration and more specifically on snippets.
Snippets is custom code that can be injected into the head
or body
elements at runtime. This is useful to inject for example analytics scripts (Google Analytics, Application Insights, …) or global UI elements.
Adding a snippet
Open your Static Web App in the Azure Portal and go to Configuration:
Select the Snippets tab and click on Add.
Now we can specify
- the location where the snippet should be injected(head or body)
- a name for our snippet
- if the snippet should be added to the beginning(prepend) or the end(append) of the location
- the environments where this should be applied
- the code itself
Click on OK to create the snippet.
If we now browse to our site, we see that the snippet is added to our page: