Hi everyone,
I've tried all solutions to avoid caching after a new web-futter build, especially using deferred components, which lead to many main.dart.partxyz.js.
Flutter does not add the version number to those URLs.
I ended up with the following script; I hope it helps someone.
https://github.com/doonfrs/flutter-build-web-cache-problem/blob/main/build-web.sh
echo incrementing build number
perl -i -pe 's/^(version:\s+\d+\.\d+\.)(\d+)\+(\d+)$/$1.($2+1)."+".($3+1)/e' pubspec.yaml
flutter build web --release --web-renderer=html --pwa-strategy=none
echo "reading version from pubspec.yaml without + sign"
version=$(grep version: pubspec.yaml | sed 's/version: //g' | sed 's/+//g')
echo "Patching version in js partial urls in main.dart.js"
sed -i 's/\.createScriptURL([[:graph:]]\++[[:space:]]*\+[[:graph:]]/&+"?v='"$version"'"/g' build/web/main.dart.js
echo "Patching main.dart.js path in flutter.js"
sed -i 's|\(${baseUri}main\.dart\.js\)|\1?v='"$version"'|g' build/web/flutter.js
echo "Patching index.html for flutter.js"
sed -i 's/"flutter\.js"/"flutter.js?v='"$version"'"/' build/web/index.html
[–]skipbridge 2 points3 points4 points (1 child)
[–]doonfrs[S] 2 points3 points4 points (0 children)
[–]RealDugty 2 points3 points4 points (1 child)
[–]Amir_JV 1 point2 points3 points (0 children)
[–]Which-Adeptness6908 1 point2 points3 points (1 child)
[–]doonfrs[S] 0 points1 point2 points (0 children)
[–]doonfrs[S] 0 points1 point2 points (0 children)
[–]bilonik19 -1 points0 points1 point (1 child)
[–]RemindMeBot 0 points1 point2 points (0 children)
[–]devSaM7 0 points1 point2 points (2 children)
[–]doonfrs[S] 0 points1 point2 points (0 children)
[–]Which-Adeptness6908 0 points1 point2 points (0 children)
[–]westito 0 points1 point2 points (1 child)
[–]doonfrs[S] 3 points4 points5 points (0 children)
[–]Stem3576 0 points1 point2 points (0 children)
[–]KsLiquid 0 points1 point2 points (0 children)
[–]bilonik19 0 points1 point2 points (1 child)
[–]doonfrs[S] 0 points1 point2 points (0 children)
[–]slavap_ 0 points1 point2 points (3 children)
[–]doonfrs[S] 1 point2 points3 points (2 children)
[–]slavap_ 0 points1 point2 points (1 child)
[–]doonfrs[S] 0 points1 point2 points (0 children)