Merge pull request #2692 from alecmerdler/webpack-cachebuster

Add Cache Busting File Hash to Webpack Bundle
This commit is contained in:
Alec Merdler 2017-06-08 15:01:26 -07:00 committed by GitHub
commit b4f1e7241f
3 changed files with 14 additions and 37 deletions

View file

@ -31,23 +31,6 @@ logger = logging.getLogger(__name__)
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,
ns_kwarg_name='namespace_name',
@ -167,7 +150,7 @@ def render_page_template(name, route_data=None, **kwargs):
library_styles = []
main_styles = []
library_scripts = []
main_scripts = ['build/quay-frontend.js']
main_scripts = list_files('build', 'js')
use_cdn = app.config.get('USE_CDN', True)
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:
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():
login_config = []
for login_service in oauth_login.services:
@ -217,10 +194,10 @@ def render_page_template(name, route_data=None, **kwargs):
route_data=route_data,
external_styles=external_styles,
external_scripts=external_scripts,
main_styles=add_cachebusters(main_styles),
library_styles=add_cachebusters(library_styles),
main_scripts=add_cachebusters(main_scripts),
library_scripts=add_cachebusters(library_scripts),
main_styles=main_styles,
library_styles=library_styles,
main_scripts=main_scripts,
library_scripts=library_scripts,
feature_set=features.get_features(),
config_set=frontend_visible_config(app.config),
oauth_set=get_oauth_config(),

View file

@ -22,12 +22,12 @@
<meta property="og:image" content="{{ preferred_scheme }}://{{ hostname }}/static/img/quay_preview.png" />
<!-- /Icons -->
{% for style_path, cache_buster in main_styles %}
<link rel="stylesheet" href="/static/{{ style_path }}?v={{ cache_buster }}" type="text/css">
{% for style_path in main_styles %}
<link rel="stylesheet" href="/static/{{ style_path }}" type="text/css">
{% endfor %}
{% for style_path, cache_buster in library_styles %}
<link rel="stylesheet" href="/static/{{ style_path }}?v={{ cache_buster }}" type="text/css">
{% for style_path in library_styles %}
<link rel="stylesheet" href="/static/{{ style_path }}" type="text/css">
{% endfor %}
{% block added_stylesheets %}
@ -57,16 +57,16 @@
<script src="{{ script_url }}"></script>
{% endfor %}
{% for script_path, cache_buster in library_scripts %}
<script src="/static/{{ script_path }}?v={{ cache_buster }}"></script>
{% for script_path in library_scripts %}
<script src="/static/{{ script_path }}"></script>
{% endfor %}
{% block added_dependencies %}
{% endblock %}
{% for script_path, cache_buster in main_scripts %}
<script src="/static/{{ script_path }}?v={{ cache_buster }}"></script>
{% for script_path in main_scripts %}
<script src="/static/{{ script_path }}"></script>
{% endfor %}
{% if sentry_public_dsn %}

View file

@ -5,7 +5,7 @@ var config = {
entry: "./static/js/main.ts",
output: {
path: path.resolve(__dirname, "static/build"),
filename: "quay-frontend.js"
filename: 'quay-frontend-[hash].js'
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".scss"],