Docker: al ?v= degli asset l'impronta del contenuto di assets/, così uno sfondo rifatto senza bump non resta nella cache lunga del browser
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiECdCPptNRwbVzjzHbohi
This commit is contained in:
@@ -17,9 +17,15 @@ COPY assets/favicon /usr/share/nginx/html/assets/favicon
|
|||||||
COPY assets/video /usr/share/nginx/html/assets/video
|
COPY assets/video /usr/share/nginx/html/assets/video
|
||||||
|
|
||||||
# Le immagini e i font citati da index.html e style.css prendono ?v=<versione>, come quelli caricati dal codice.
|
# Le immagini e i font citati da index.html e style.css prendono ?v=<versione>, come quelli caricati dal codice.
|
||||||
|
# Alla versione si aggiunge l'impronta del contenuto di assets/: uno sfondo rifatto senza cambiare versione (in
|
||||||
|
# locale, fra un bump e l'altro) ha un indirizzo nuovo, e il browser non tiene quello vecchio dalla cache lunga.
|
||||||
RUN cd /usr/share/nginx/html \
|
RUN cd /usr/share/nginx/html \
|
||||||
&& V=$(sed -n "s/^export const VERSION = '\([0-9.]*\)';$/\1/p" src/version.js) \
|
&& V=$(sed -n "s/^export const VERSION = '\([0-9.]*\)';$/\1/p" src/version.js) \
|
||||||
&& test -n "$V" \
|
&& test -n "$V" \
|
||||||
|
&& H=$(find assets -type f -exec md5sum {} + | sort -k2 | md5sum | cut -c1-8) \
|
||||||
|
&& sed -i -E 's#v=\$\{VERSION\}#v=${VERSION}-'"$H"'#' src/version.js \
|
||||||
|
&& grep -q "VERSION}-$H" src/version.js \
|
||||||
|
&& V="$V-$H" \
|
||||||
&& sed -i -E "s#url\((assets/[^)]*)\)#url(\1?v=$V)#g" style.css \
|
&& sed -i -E "s#url\((assets/[^)]*)\)#url(\1?v=$V)#g" style.css \
|
||||||
&& sed -i -E "s#src=\"(assets/[^\"]*)\"#src=\"\1?v=$V\"#g" index.html \
|
&& sed -i -E "s#src=\"(assets/[^\"]*)\"#src=\"\1?v=$V\"#g" index.html \
|
||||||
&& grep -q "?v=$V" style.css && grep -q "?v=$V" index.html
|
&& grep -q "?v=$V" style.css && grep -q "?v=$V" index.html
|
||||||
|
|||||||
Reference in New Issue
Block a user