Skip to content

Commit

Permalink
front end resource cache busting
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklamers committed Jun 10, 2020
1 parent bf97a2c commit a214782
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions orchest/orchest-webserver/app/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Config:
USER_DIR = os.path.join("/userdir")
HOST_USER_DIR = os.environ.get("HOST_USER_DIR")
LOG_DIR = ".logs"
STATIC_DIR = os.path.join(dir_path, "../static")

ORCHEST_API_ADDRESS = "orchest-api"

Expand Down
4 changes: 2 additions & 2 deletions orchest/orchest-webserver/app/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- External dependencies -->
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

<link rel="stylesheet" href="public/css/main.css"/>
<link rel="stylesheet" href="public/css/main.css?v={{ css_bundle_hash }}"/>
<link rel="icon" href="public/image/favicon.png" type="image/x-icon"/>

</head>
Expand Down Expand Up @@ -74,6 +74,6 @@ <h1 class="logo"><img src="public/image/logo.png" width="60%" /></h1>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>

<script type="module" src="public/js/dist/main.bundle.js"></script>
<script type="module" src="public/js/dist/main.bundle.js?v={{ javascript_bundle_hash }}"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions orchest/orchest-webserver/app/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import json
import os
import hashlib
import random
import string

def get_hash(path):
BLOCKSIZE = 8192 * 8
hasher = hashlib.md5()
with open(path, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)

return hasher.hexdigest()


def write_config(app, key, value):

Expand Down
8 changes: 7 additions & 1 deletion orchest/orchest-webserver/app/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
import nbformat
from nbconvert import HTMLExporter

from app.utils import get_hash

logging.basicConfig(level=logging.DEBUG)

def register_views(app, db):

@app.route("/", methods=["GET"])
def index():
return render_template("index.html")

js_bundle_path = os.path.join(app.config["STATIC_DIR"], "js/dist/main.bundle.js")
css_bundle_path = os.path.join(app.config["STATIC_DIR"], "css/main.css")

return render_template("index.html", javascript_bundle_hash = get_hash(js_bundle_path), css_bundle_hash = get_hash(css_bundle_path))


@app.route("/catch/api-proxy/api/runs/", methods=["POST"])
Expand Down

0 comments on commit a214782

Please sign in to comment.