From ee0542256e87d80aca3953c6f31c1280e0e54658 Mon Sep 17 00:00:00 2001 From: Alexei Bendebury Date: Tue, 23 Aug 2016 11:05:55 -0700 Subject: [PATCH 1/2] Trying to fix sri fallback --- quizApp/static/js/sri-fallback.js | 22 +++++++++++++++++----- quizApp/templates/layout.html | 6 ++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/quizApp/static/js/sri-fallback.js b/quizApp/static/js/sri-fallback.js index d8d3cbd..3291cf5 100644 --- a/quizApp/static/js/sri-fallback.js +++ b/quizApp/static/js/sri-fallback.js @@ -1,11 +1,23 @@ function resource_error(element) { var fallback_url = element.dataset.fallback; + console.log("Fallback: " + fallback_url); var is_js = fallback_url.substr(fallback_url.length - 3) == ".js"; - - if (is_js) { - document.write(""); + if(is_js) { + var script = document.createElement('script'); + script.src = fallback_url; + document.head.appendChild(script); } else { - // Assume we have jquery loaded by now - $('head').append(""); + var link = document.createElement('link'); + link.href = fallback_url; + link.rel = "stylesheet"; + document.head.appendChild(link); + } +} + +function check_js_error(condition, fallback) { + if(!condition) { + var script = document.createElement('script'); + script.src = fallback_url; + document.head.appendChild(script); } } diff --git a/quizApp/templates/layout.html b/quizApp/templates/layout.html index 18601d6..5c4d20c 100644 --- a/quizApp/templates/layout.html +++ b/quizApp/templates/layout.html @@ -24,6 +24,12 @@ integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" data-fallback="{{ url_for('static', filename='js/jquery.min.js') }}" crossorigin="anonymous" onerror="resource_error(this)"> + Date: Wed, 14 Sep 2016 10:25:29 -0700 Subject: [PATCH 2/2] Trying to find sri solution --- quizApp/static/js/sri-fallback.js | 4 ++-- quizApp/templates/layout.html | 14 ++++++++++++-- quizApp/templates/macros.html | 20 ++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/quizApp/static/js/sri-fallback.js b/quizApp/static/js/sri-fallback.js index 3291cf5..e51d4f9 100644 --- a/quizApp/static/js/sri-fallback.js +++ b/quizApp/static/js/sri-fallback.js @@ -17,7 +17,7 @@ function resource_error(element) { function check_js_error(condition, fallback) { if(!condition) { var script = document.createElement('script'); - script.src = fallback_url; - document.head.appendChild(script); + script.src = fallback; + document.write(" - + @@ -51,10 +53,18 @@ integrity="sha384-FFgGfda92tXC8nCNOxrCQ3R8x1TNkMFqDZVQdDaaJiiVbjkPBXIJBx0o7ETjy8Bh" data-fallback="{{ url_for('static', filename='js/html5shiv.min.js') }}" crossorigin="anonymous" onerror="resource_error(this)"> + + {% block head %}{% endblock %} diff --git a/quizApp/templates/macros.html b/quizApp/templates/macros.html index efd6955..342af40 100644 --- a/quizApp/templates/macros.html +++ b/quizApp/templates/macros.html @@ -209,7 +209,11 @@ defer integrity="sha384-ohw6o2vy/chIavW0iVsUoWaIPmAnF9VKjEMSusADB79PrE3CdeJhvR84BjcynjVl" data-fallback="{{ url_for('static', filename='js/moment.min.js') }}" - crossorigin="anonymous" onerror="resource_error(this)"> + crossorigin="anonymous"> + @@ -223,12 +227,20 @@ integrity="sha384-89aj/hOsfOyfD0Ll+7f2dobA15hDyiNb8m1dJ+rJuqgrGR+PVqNU8pybx4pbF3Cc" data-fallback="{{ url_for('static', filename='js/jquery.dataTables.min.js') }}" defer - crossorigin="anonymous" onerror="resource_error(this)"> + crossorigin="anonymous"> + + crossorigin="anonymous"> +