To maintain old assets in Azure Static Web Apps during new deployments, you can consider the following workaround:
Azure Blob Storage: Use Azure Blob Storage to store your assets. You can upload your build artifacts to Blob Storage and reference them in your app. This way, even after a new deployment, the old assets will remain available. You can automate this process using Azure Pipelines or GitHub Actions.
- Cache-Control Headers: Set appropriate cache-control headers for your assets. By setting a long
max-age
, you can ensure that users’ browsers keep a cached version of the asset for a longer period. However, this won’t prevent the issue if the cached version expires or if the user clears their cache. Versioning: Implement a versioning system for your assets. For example, you could have a folder structure based on version numbers and keep multiple versions of your assets. Your application logic would need to handle loading the correct version based on the user’s session. Custom Deployment Script: Create a custom deployment script that copies the current assets to a backup location before the new deployment. After the deployment, the script can restore the assets from the backup location. Service Workers: If you’re using service workers, you can manage asset caching and versioning through them. Service workers can intercept network requests and serve the appropriate version of an asset from the cache. Incremental Deployment: Explore the possibility of incremental deployments, where only changed files are updated, and unchanged files are left as is. This might require custom scripting or tooling to compare file versions before deployment.