Skip to content
Permalink
Browse files

Serivce worker and manifest to allow offline usage

  • Loading branch information...
keyz182 committed Mar 5, 2018
1 parent f2d3ec5 commit be9568566e920d3518fd8cce39877869426cbfee
Showing with 88 additions and 1 deletion.
  1. +6 −0 .idea/vcs.xml
  2. +13 −1 index.html
  3. +8 −0 manifest.json
  4. +61 −0 sw.js
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
@@ -11,6 +11,8 @@
<link rel="stylesheet" type="text/css" href="vendor/bootstrap-slider/css/bootstrap-slider.min.css" />
<link rel="stylesheet" type="text/css" href="vendor/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="manifest" href="./manifest.json">

</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
@@ -366,7 +368,17 @@ <h3 class="panel-title">Colors</h3>
<!-- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> -->
<p class="message">Alert message empty...</p>
</div>

<script type="text/javascript">
if (navigator.serviceWorker) {
navigator.serviceWorker.register('sw.js', {scope: '/'}).then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
</script>
<script src="vendor/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="vendor/jquery-ui/jquery-ui.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
@@ -0,0 +1,8 @@
{
"short_name": "SLAcer.js",
"name": "SLAcer.js (bêta)",
"description": "SLAcer.js (bêta)",
"start_url": "./index.html",
"display": "standalone",
"orientation": "landscape"
}
61 sw.js
@@ -0,0 +1,61 @@
// Use a cacheName for cache versioning
var cacheName = 'v1:static';
var cacheFiles = [
'./',
'index.html',
'./index.html',
'./css/main.css',
'./js/main.js',
'./js/loader/stl.js',
'./js/slacer/mesh.js',
'./js/slacer/settings.js',
'./js/slacer/slicer.js',
'./js/slacer/viewer.js',
'./js/slacer/viewcontrols.js',
'./js/slacer/viewer2d.js',
'./js/slacer/viewer3d.js',
'./vendor/jquery-ui/jquery-ui.min.css',
'./vendor/bootstrap/css/bootstrap.min.css',
'./vendor/bootstrap-slider/css/bootstrap-slider.min.css',
'./vendor/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css',
'./vendor/jquery-2.1.4.min.js',
'./vendor/jquery-ui/jquery-ui.min.js',
'./vendor/bootstrap/js/bootstrap.min.js',
'./vendor/bootstrap-slider/bootstrap-slider.min.js',
'./vendor/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js',
'./vendor/lodash.min.js',
'./vendor/three.min.js',
'./vendor/earcut.js',
'./vendor/triangulation.js',
'./vendor/OrbitControls.js',
'./vendor/FileSaver.min.js',
'./vendor/jszip.min.js'
];

// During the installation phase, you'll usually want to cache static assets.
self.addEventListener('install', function(e) {
// Once the service worker is installed, go ahead and fetch the resources to make this work offline.
console.log('install');
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(cacheFiles).then(function() {
self.skipWaiting();
});
})
);
});

// when the browser fetches a URL…
self.addEventListener('fetch', function(event) {
// … either respond with the cached object or go ahead and fetch the actual URL
event.respondWith(
caches.match(event.request).then(function(resp) {
return resp || fetch(event.request).then(function(response) {
return caches.open(cacheName).then(function(cache) {
cache.put(event.request, response.clone());
return response;
});
});
})
);
});

0 comments on commit be95685

Please sign in to comment.
You can’t perform that action at this time.