Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webworker cache #8271

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const bodyParser = require('body-parser');

const path = require('path');
const fs = require('fs');
const ejs = require('ejs');

function create (env, ctx) {
var app = express();
Expand Down Expand Up @@ -92,6 +93,15 @@ function create (env, ctx) {
}
app.locals.cachebuster = cacheBuster;

app.get("/sw.js", (req, res) => {
res.setHeader('Content-Type', 'application/javascript');
res.send(ejs.render(fs.readFileSync(
require.resolve(`${__dirname}/views/service-worker.js`),
{ encoding: 'utf-8' }),
{ locals: app.locals}
));
});

if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/server/booterror')(ctx));
return app;
Expand Down Expand Up @@ -178,12 +188,6 @@ function create (env, ctx) {

app.use("/clock", clockviews);

app.get("/appcache/*", (req, res) => {
res.render("nightscout.appcache", {
locals: app.locals
});
});

app.use('/api', bodyParser({
limit: 1048576 * 50
}), apiRoot);
Expand Down
10 changes: 5 additions & 5 deletions views/adminindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<meta name="theme-color" content="#333333">


<link rel="preload" href="/css/main.css?v=<%= locals.cachebuster %>" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/main.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/drawer.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/admin.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/ui-darkness/jquery-ui.min.css?v=<%= locals.cachebuster %>" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/ui-darkness/jquery-ui.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<% include preloadCSS %>
</head>
<body>
Expand All @@ -39,8 +39,8 @@

<%- include('partials/authentication-status') %>

<script src="<%= locals.bundle %>/js/bundle.app.js?v=<%= locals.cachebuster %>"></script>
<script src="/socket.io/socket.io.js?v=<%= locals.cachebuster %>"></script>
<script src="/admin/js/admin.js?v=<%= locals.cachebuster %>"></script>
<script src="<%= locals.bundle %>/js/bundle.app.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/admin/js/admin.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion views/clockviews/shared.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<div id="staleTime"></div>
</div>
</main>
<script src="<%= locals.bundle %>/js/bundle.clock.js?v=<%= locals.cachebuster %>"></script>
<script src="<%= locals.bundle %>/js/bundle.clock.js"></script>

<script type="text/javascript">
var clockFace = "<%= face %>"; // can now be used in scripts
Expand Down
10 changes: 5 additions & 5 deletions views/foodindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<meta name="msapplication-config" content="/browserconfig.xml">
<meta name="theme-color" content="#333333">

<link rel="preload" href="/css/main.css?v=<%= locals.cachebuster %>" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/main.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/dropdown.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/drawer.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/food.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/ui-darkness/jquery-ui.min.css?v=<%= locals.cachebuster %>" as="style" onload="this.onload=null;this.rel='stylesheet'">
<link rel="preload" href="/css/ui-darkness/jquery-ui.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
<% include preloadCSS %>

</head>
Expand Down Expand Up @@ -112,8 +112,8 @@

<%- include('partials/authentication-status') %>

<script src="<%= locals.bundle %>/js/bundle.app.js?v=<%= locals.cachebuster %>"></script>
<script src="/socket.io/socket.io.js?v=<%= locals.cachebuster %>"></script>
<script src="/food/js/food.js?v=<%= locals.cachebuster %>"></script>
<script src="<%= locals.bundle %>/js/bundle.app.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/food/js/food.js"></script>
</body>
</html>
Loading