Search code examples
versioningflutter-webfirebase-hosting

How to update version of a Flutter Web deployed in Firebase Hosting


In older versions of Flutter, the web/index.html file was built with a script inside that calls main.dart.js but this script was removed in newer versions and I used to add a "version" attribute to specify the version, how to update the version of my flutter web deployed on Firebase Hosting? Is there any other way to that now?

/// Original
<script src="main.dart.js" type="application/javascript"></script>

/// Modified
<script src="main.dart.js?version=10" type="application/javascript"></script>

Solution

  • I ended up adding this script manually inside the body tag and disabled cache in firebase.json file.

    index.html

    <script src="main.dart.js?version=10" type="application/javascript"></script>
    

    firebase.json

    {
      "hosting": {
        "public": "build/web",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
    
        "headers": [
    
          {
            "source": "**",
            "headers": [
              {
                "key": "Cache-Control",
                "value": "no-cache"
              }
            ]
          }
    
        ]
      }
    
    
    }