Merge pull request #2692 from alecmerdler/webpack-cachebuster
Add Cache Busting File Hash to Webpack Bundle
This commit is contained in:
commit
b4f1e7241f
3 changed files with 14 additions and 37 deletions
|
@ -31,23 +31,6 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
route_data = None
|
route_data = None
|
||||||
|
|
||||||
CACHE_BUSTERS_JSON = 'static/dist/cachebusters.json'
|
|
||||||
CACHE_BUSTERS = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_cache_busters():
|
|
||||||
""" Retrieves the cache busters hashes. """
|
|
||||||
global CACHE_BUSTERS
|
|
||||||
if CACHE_BUSTERS is not None:
|
|
||||||
return CACHE_BUSTERS
|
|
||||||
|
|
||||||
if not os.path.exists(CACHE_BUSTERS_JSON):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
with open(CACHE_BUSTERS_JSON, 'r') as f:
|
|
||||||
CACHE_BUSTERS = json.loads(f.read())
|
|
||||||
return CACHE_BUSTERS
|
|
||||||
|
|
||||||
|
|
||||||
def parse_repository_name(include_tag=False,
|
def parse_repository_name(include_tag=False,
|
||||||
ns_kwarg_name='namespace_name',
|
ns_kwarg_name='namespace_name',
|
||||||
|
@ -167,7 +150,7 @@ def render_page_template(name, route_data=None, **kwargs):
|
||||||
library_styles = []
|
library_styles = []
|
||||||
main_styles = []
|
main_styles = []
|
||||||
library_scripts = []
|
library_scripts = []
|
||||||
main_scripts = ['build/quay-frontend.js']
|
main_scripts = list_files('build', 'js')
|
||||||
|
|
||||||
use_cdn = app.config.get('USE_CDN', True)
|
use_cdn = app.config.get('USE_CDN', True)
|
||||||
if request.args.get('use_cdn') is not None:
|
if request.args.get('use_cdn') is not None:
|
||||||
|
@ -180,12 +163,6 @@ def render_page_template(name, route_data=None, **kwargs):
|
||||||
if features.BILLING:
|
if features.BILLING:
|
||||||
external_scripts.append('//checkout.stripe.com/checkout.js')
|
external_scripts.append('//checkout.stripe.com/checkout.js')
|
||||||
|
|
||||||
def add_cachebusters(filenames):
|
|
||||||
cachebusters = get_cache_busters()
|
|
||||||
for filename in filenames:
|
|
||||||
cache_buster = cachebusters.get(filename, random_string()) if not debugging else 'debugging'
|
|
||||||
yield (filename, cache_buster)
|
|
||||||
|
|
||||||
def get_external_login_config():
|
def get_external_login_config():
|
||||||
login_config = []
|
login_config = []
|
||||||
for login_service in oauth_login.services:
|
for login_service in oauth_login.services:
|
||||||
|
@ -217,10 +194,10 @@ def render_page_template(name, route_data=None, **kwargs):
|
||||||
route_data=route_data,
|
route_data=route_data,
|
||||||
external_styles=external_styles,
|
external_styles=external_styles,
|
||||||
external_scripts=external_scripts,
|
external_scripts=external_scripts,
|
||||||
main_styles=add_cachebusters(main_styles),
|
main_styles=main_styles,
|
||||||
library_styles=add_cachebusters(library_styles),
|
library_styles=library_styles,
|
||||||
main_scripts=add_cachebusters(main_scripts),
|
main_scripts=main_scripts,
|
||||||
library_scripts=add_cachebusters(library_scripts),
|
library_scripts=library_scripts,
|
||||||
feature_set=features.get_features(),
|
feature_set=features.get_features(),
|
||||||
config_set=frontend_visible_config(app.config),
|
config_set=frontend_visible_config(app.config),
|
||||||
oauth_set=get_oauth_config(),
|
oauth_set=get_oauth_config(),
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
<meta property="og:image" content="{{ preferred_scheme }}://{{ hostname }}/static/img/quay_preview.png" />
|
<meta property="og:image" content="{{ preferred_scheme }}://{{ hostname }}/static/img/quay_preview.png" />
|
||||||
<!-- /Icons -->
|
<!-- /Icons -->
|
||||||
|
|
||||||
{% for style_path, cache_buster in main_styles %}
|
{% for style_path in main_styles %}
|
||||||
<link rel="stylesheet" href="/static/{{ style_path }}?v={{ cache_buster }}" type="text/css">
|
<link rel="stylesheet" href="/static/{{ style_path }}" type="text/css">
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for style_path, cache_buster in library_styles %}
|
{% for style_path in library_styles %}
|
||||||
<link rel="stylesheet" href="/static/{{ style_path }}?v={{ cache_buster }}" type="text/css">
|
<link rel="stylesheet" href="/static/{{ style_path }}" type="text/css">
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% block added_stylesheets %}
|
{% block added_stylesheets %}
|
||||||
|
@ -57,16 +57,16 @@
|
||||||
<script src="{{ script_url }}"></script>
|
<script src="{{ script_url }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% for script_path, cache_buster in library_scripts %}
|
{% for script_path in library_scripts %}
|
||||||
<script src="/static/{{ script_path }}?v={{ cache_buster }}"></script>
|
<script src="/static/{{ script_path }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% block added_dependencies %}
|
{% block added_dependencies %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% for script_path, cache_buster in main_scripts %}
|
{% for script_path in main_scripts %}
|
||||||
<script src="/static/{{ script_path }}?v={{ cache_buster }}"></script>
|
<script src="/static/{{ script_path }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if sentry_public_dsn %}
|
{% if sentry_public_dsn %}
|
||||||
|
|
|
@ -5,7 +5,7 @@ var config = {
|
||||||
entry: "./static/js/main.ts",
|
entry: "./static/js/main.ts",
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "static/build"),
|
path: path.resolve(__dirname, "static/build"),
|
||||||
filename: "quay-frontend.js"
|
filename: 'quay-frontend-[hash].js'
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: [".ts", ".tsx", ".js", ".scss"],
|
extensions: [".ts", ".tsx", ".js", ".scss"],
|
||||||
|
|
Reference in a new issue