Skip to content

Commit

Permalink
fix appcache update
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan You committed Mar 4, 2013
1 parent 5f35470 commit e5dd2d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ echo "\033[32m[minify]\033[0m rewriting script tag in" $BASEDIR"/deploy/template
sed -i.bak '/<script.*\/script>/d' $BASEDIR/deploy/index.html
#2. replace <!-- MIN --> tag with min.js
sed -i.bak 's/<!-- MIN -->/<script src="js\/min.js"><\/script>/' $BASEDIR/deploy/index.html
#3. add appcache manifest
sed -i.bak 's/<html>/<html manifest="offline.appcache">/' $BASEDIR/deploy/index.html

#minify javascript with uglifyjs

Expand Down
21 changes: 13 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html manifest="offline.appcache">
<html>
<head>
<title>HTML5 Clear</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Expand Down Expand Up @@ -37,13 +37,18 @@
</script>

<script>
var appCache = window.applicationCache;
if (appCache) {
appCache.update();
if (appCache.status == window.applicationCache.UPDATEREADY) {
appCache.swapCache(); // The fetch was successful, swap in the new cache.
}
}
window.addEventListener('load', function(e) {

window.applicationCache.addEventListener('updateready', function(e) {
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
window.applicationCache.swapCache();
if (confirm('A new version of the app is available. Load it?')) {
window.location.reload();
}
}
}, false);

}, false);
</script>

<script src="js/zepto.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion offline.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# 2013-03-04:v4
# 2013-03-04:v5

index.html
css/style.css
Expand Down

0 comments on commit e5dd2d8

Please sign in to comment.