Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
318 stars 53 forks source link

Static content compression is not working #1340

Open milanm opened 7 months ago

milanm commented 7 months ago

We serve Vue.js 3 static web app on the Azure Static Web Apps, built using Vite. It works fine, but all returned Content-Encoding is empty on .css, .js, and. HTML files. So, all files come uncompressed.

We created the Static Site via the Terraform approach:

resource "azurerm_static_site" "spa1" {
  name                           = "${var.app_service_name}Spa1${title(var.environment)}"
  location                       = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  sku_tier                        = "Standard"
  sku_size                        = "Standard"
}

And the app is deployed via Azure DevOps pipelines:

- deployment: Deploy
    displayName: Deploy
    environment: Development
    pool: 
      vmImage: ubuntu-20.04
    strategy:
      runOnce:
        deploy:
          steps:
          - task: DownloadPipelineArtifact@2
            displayName: 'Download Artifacts'
            inputs:
              buildType: 'current'
              targetPath: '$(Pipeline.Workspace)'    
          - task: ExtractFiles@1
            displayName: 'Extract files'
            inputs:
               archiveFilePatterns: '/home/vsts/work/1/spa/development/node.zip'
               destinationFolder: '$(Build.ArtifactStagingDirectory)/out'
               cleanDestinationFolder: false   
          - task: AzureStaticWebApp@0
            inputs:
              app_location: '/out'
              api_location: ''
              output_location: ''
              skip_app_build: true
              is_static_export: true
              azure_static_web_apps_api_token: $(azureStaticWebAppsApiToken)
              workingDirectory: $(Build.ArtifactStagingDirectory)

Our staticwebapp.config.json file looks like this:

{
  "globalHeaders": {
    "content-security-policy": "default-src https: 'unsafe-eval' 'unsafe-inline'; object-src 'none'"
  },
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": ["/img/*.{png,jpg,gif,webp}", "/css/*"]
  },
  "mimeTypes": {
    "custom": "text/html"
  }
}

When we turned off Enterprise-grade edge, it started to use Content-encoding: br.

Is this a bug, or have we missed something?

thomasgauvin commented 7 months ago

Are you indicating that you have no content-encoding for SWAs with enterprise-grade edge? Do the files you are looking at fall under AFDs compression rules? https://learn.microsoft.com/en-us/azure/frontdoor/standard-premium/how-to-compression#compression-rules

milanm commented 7 months ago

Yes, I tested a few .js files with the size of 1-3Mbs.

Another issue now: I turned off enterprise-grade edge yesterday, and now when I want to turn it on, it says the following error:

Failed to enable edge with error: Cannot update enterprise-grade CDN on static web app MyApp because another update operation to this static web app is in progress.

It seems this is the issue: https://github.com/Azure/static-web-apps/issues/691

ImpactMAC commented 5 months ago

We're experiencing the same issue. Dev environments are running without enterprise-grade edge and is using compression just fine, but our production app (running with enterprise-grade edge) is not. :(

Kinda a big issue, since we're using the edge to get better performance, but it is actually worse in some ways.

imichalarias commented 4 months ago

we experience the same issue for an Angular app

rrkpt commented 4 months ago

Hi, I'm experiencing the same issue with my Angular app. So, when I enable enterprise-grade edge - files are not compressed. May I check if we are doing anything wrong, or if there are any plans to resolve this issue? Thanks in advance.

thomasgauvin commented 4 months ago

Can you share a reproduction of this? I'm not able to reproduce this issue but would want to better understand what's happening. Also, if this warrants a more speedy resolution, I would recommend directly opening a support thread such that there are folks tooled to investigate this issue.

ELuscia commented 2 months ago

Hi, I am experiencing the same issue, I have a SWA using Enterprise edge and files are being returned without encoding, I have confirmed the files are of a supported type (.json and JPG) and the size from 1KB to 3MB, is this a known issue with enterprise-grade edge or is there something that should be configured or enabled?

vinhent commented 2 months ago

We are experiencing the same issue. When enterprise-grade edge is enabled the compression is not working and it affects the performance.

nipundave commented 1 week ago

Same issue here as well. Can someone from Azure SWA team share an ETA to enable this feature?