Skip to content

Commit 25b3438

Browse files
committed
add appcache for docs site - caches only css/js/img resources
1 parent f21b921 commit 25b3438

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ task :package => [:clean, :compile, :docs] do
241241
f.write text.sub('angular-scenario.js', "angular-scenario-#{version}.js")
242242
end
243243

244+
File.open("#{pkg_dir}/docs-#{version}/app-cache.manifest", File::RDWR) do |f|
245+
text = f.read
246+
f.rewind
247+
f.write text.sub('angular.min.js', "angular-#{version}.min.js")
248+
end
249+
250+
244251
%x(tar -czf #{path_to(tarball)} -C #{path_to('pkg')} .)
245252

246253
puts "Package created: #{path_to(tarball)}"

docs/src/gen-docs.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var writes = callback.chain(function(){
2727
writer.copyDir('img', writes.waitFor());
2828
writer.copyDir('examples', writes.waitFor());
2929
writer.copyTpl('index.html', writes.waitFor());
30+
writer.copyTpl('offline.html', writes.waitFor());
31+
writer.output('app-cache.manifest',
32+
appCacheTemplate().replace(/%TIMESTAMP%/, (new Date()).toISOString()),
33+
writes.waitFor());
3034
writer.merge(['docs.js',
3135
'doc_widgets.js'],
3236
'docs-combined.js',
@@ -59,3 +63,28 @@ writer.makeDir('build/docs/syntaxhighlighter', work);
5963

6064
///////////////////////////////////
6165
function now(){ return new Date().getTime(); }
66+
67+
68+
function appCacheTemplate() {
69+
return ["CACHE MANIFEST",
70+
"# %TIMESTAMP%",
71+
"",
72+
"# cache all of these",
73+
"CACHE:",
74+
"jquery.min.js",
75+
"syntaxhighlighter/syntaxhighlighter-combined.js",
76+
"../angular.min.js",
77+
"docs-combined.js",
78+
"docs-keywords.js",
79+
"docs-combined.css",
80+
"syntaxhighlighter/syntaxhighlighter-combined.css",
81+
"img/texture_1.png",
82+
"img/yellow_bkgnd.jpg",
83+
"",
84+
"FALLBACK:",
85+
"/ offline.html",
86+
"",
87+
"# allow access to google analytics and twitter when we are online",
88+
"NETWORK:",
89+
"*"].join('\n');
90+
}

docs/src/templates/index.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<!doctype html>
22
<html xmlns:ng="http://angularjs.org/"
33
xmlns:doc="http://docs.angularjs.org/"
4-
ng:controller="DocsController">
4+
ng:controller="DocsController"
5+
manifest="app-cache.manifest">
56
<head>
67
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
78
<title ng:bind-template="&lt;angular/&gt;: {{partialTitle}}">&lt;angular/&gt;</title>
@@ -20,6 +21,14 @@
2021
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
2122
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
2223
})();
24+
25+
// force page reload when new update is available
26+
window.applicationCache && window.applicationCache.addEventListener('updateready', function(e) {
27+
if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
28+
window.applicationCache.swapCache();
29+
window.location.reload();
30+
}
31+
}, false);
2332
</script>
2433
</head>
2534

docs/src/templates/offline.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h2>OFFLINE</h2>
2+
3+
<p>This page if unavailable because your are offline.</p>
4+
<p>Please connect to the Internet and reload the page.</p>

lib/nodeserver/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ StaticServlet.MimeMap = {
7979
'jpg': 'image/jpeg',
8080
'jpeg': 'image/jpeg',
8181
'gif': 'image/gif',
82-
'png': 'image/png'
82+
'png': 'image/png',
83+
'manifest': 'text/cache-manifest'
8384
};
8485

8586
StaticServlet.prototype.handleRequest = function(req, res) {

0 commit comments

Comments
 (0)