Skip to content

Commit 1c5d267

Browse files
authored
Merge pull request #1 from FrankFlitton/cache-breaking
Cache breaking
2 parents acfcd7b + 59d8613 commit 1c5d267

File tree

3 files changed

+91
-17
lines changed

3 files changed

+91
-17
lines changed

example_app/.gitignore renamed to .gitignore

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,28 @@
2323
# Flutter/Dart/Pub related
2424
**/doc/api/
2525
**/ios/Flutter/.last_build_id
26-
.dart_tool/
27-
.flutter-plugins
28-
.flutter-plugins-dependencies
29-
.packages
30-
.pub-cache/
31-
.pub/
32-
/build/
26+
example_app/.dart_tool/
27+
example_app/.flutter-plugins
28+
example_app/.flutter-plugins-dependencies
29+
example_app/.packages
30+
example_app/.pub-cache/
31+
example_app/.pub/
32+
example_app/build/
33+
example_app/flutter/
3334

3435
# Web related
35-
lib/generated_plugin_registrant.dart
36+
example_app/lib/generated_plugin_registrant.dart
3637

3738
# Symbolication related
38-
app.*.symbols
39+
example_app/app.*.symbols
3940

4041
# Obfuscation related
41-
app.*.map.json
42+
example_app/app.*.map.json
4243

4344
# Android Studio will place build artifacts here
44-
/android/app/debug
45-
/android/app/profile
46-
/android/app/release
45+
example_app/android/app/debug
46+
example_app/android/app/profile
47+
example_app/android/app/release
48+
49+
# Local Netlify folder
50+
.netlify

build-web.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# Reminder to check for updates to the build script.
1212
# Flutter for web is still in beta so expect updates!
1313

14-
CURRENT_VERSION=1.0.1
14+
CURRENT_VERSION=1.1.0
1515
REMOTE_URL="https://github.com/FrankFlitton/Flutter-for-web-deploy-script"
16-
REMOTE_TAGS="$(git ls-remote --tags $REMOTE_URL)"
16+
REMOTE_TAGS="$(echo $(git ls-remote --tags $REMOTE_URL))"
1717

1818
REMOTE_HASHES=()
1919
REMOTE_VERSIONS=()
@@ -98,4 +98,39 @@ $FLUTTER_BIN build web --release
9898
echo "🚚🖼 Copying graphic assets to their expected folders"
9999
cp -R $APP_DIR/build/web/assets/. $APP_DIR/build/web/
100100

101+
# Start cache breaking
102+
103+
BUILD_HASH=$((1 + $RANDOM % 100000))
104+
HASHED_FILE=""
105+
106+
fileExtHash() {
107+
SEPERATOR=$(echo $1 | tail -c 2)
108+
F_EXT=$(echo $1 | cut -d"$SEPERATOR" -f 1)
109+
HASHED_EXT=$F_EXT"?"$BUILD_HASH$SEPERATOR
110+
HASHED_FILE=$HASHED_EXT
111+
}
112+
113+
replacePath() {
114+
INPUT_FILE=$1
115+
TARGET_EXT=$2
116+
TARGET_HASHED_EXT=$3
117+
cat $INPUT_FILE | awk -v srch="$TARGET_EXT" -v repl="$TARGET_HASHED_EXT" '{ sub(srch,repl,$0); print $0 }' >tmp && mv tmp $INPUT_FILE
118+
}
119+
120+
# Force new js to be loaded by the browser.
121+
# Breaking cache on js and json files in index.html
122+
123+
HTML_EXTS=("js" "json")
124+
125+
echo "✅📦 Hashing assets for this release"
126+
127+
for EXT_ROOT in ${HTML_EXTS[@]}; do
128+
# echo $EXT
129+
EXT_LIST=("."$EXT_ROOT\" "."$EXT_ROOT\')
130+
for EXT in ${EXT_LIST[@]}; do
131+
fileExtHash $EXT
132+
replacePath $APP_DIR/build/web/index.html $EXT $HASHED_FILE
133+
done
134+
done
135+
101136
echo "✅🦋 Flutter for web build pipeline complete!"

example_app/build-web.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# Reminder to check for updates to the build script.
1212
# Flutter for web is still in beta so expect updates!
1313

14-
CURRENT_VERSION=1.0.1
14+
CURRENT_VERSION=1.1.0
1515
REMOTE_URL="https://github.com/FrankFlitton/Flutter-for-web-deploy-script"
16-
REMOTE_TAGS="$(git ls-remote --tags $REMOTE_URL)"
16+
REMOTE_TAGS="$(echo $(git ls-remote --tags $REMOTE_URL))"
1717

1818
REMOTE_HASHES=()
1919
REMOTE_VERSIONS=()
@@ -98,4 +98,39 @@ $FLUTTER_BIN build web --release
9898
echo "🚚🖼 Copying graphic assets to their expected folders"
9999
cp -R $APP_DIR/build/web/assets/. $APP_DIR/build/web/
100100

101+
# Start cache breaking
102+
103+
BUILD_HASH=$((1 + $RANDOM % 100000))
104+
HASHED_FILE=""
105+
106+
fileExtHash() {
107+
SEPERATOR=$(echo $1 | tail -c 2)
108+
F_EXT=$(echo $1 | cut -d"$SEPERATOR" -f 1)
109+
HASHED_EXT=$F_EXT"?"$BUILD_HASH$SEPERATOR
110+
HASHED_FILE=$HASHED_EXT
111+
}
112+
113+
replacePath() {
114+
INPUT_FILE=$1
115+
TARGET_EXT=$2
116+
TARGET_HASHED_EXT=$3
117+
cat $INPUT_FILE | awk -v srch="$TARGET_EXT" -v repl="$TARGET_HASHED_EXT" '{ sub(srch,repl,$0); print $0 }' >tmp && mv tmp $INPUT_FILE
118+
}
119+
120+
# Force new js to be loaded by the browser.
121+
# Breaking cache on js and json files in index.html
122+
123+
HTML_EXTS=("js" "json")
124+
125+
echo "✅📦 Hashing assets for this release"
126+
127+
for EXT_ROOT in ${HTML_EXTS[@]}; do
128+
# echo $EXT
129+
EXT_LIST=("."$EXT_ROOT\" "."$EXT_ROOT\')
130+
for EXT in ${EXT_LIST[@]}; do
131+
fileExtHash $EXT
132+
replacePath $APP_DIR/build/web/index.html $EXT $HASHED_FILE
133+
done
134+
done
135+
101136
echo "✅🦋 Flutter for web build pipeline complete!"

0 commit comments

Comments
 (0)