Skip to content

Instantly share code, notes, and snippets.

@lewiscowper
Forked from anonymous/StationStatus.xml
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewiscowper/f10dacb0c58ae8db0d83 to your computer and use it in GitHub Desktop.
Save lewiscowper/f10dacb0c58ae8db0d83 to your computer and use it in GitHub Desktop.
date
Sun, 19 Apr 2015 13:41:28 GMT
via
1.1 vegur
x-aspnet-version
4.0.30319
x-powered-by
ASP.NET
x-final-url
http://cloud.tfl.gov.uk/TrackerNet/lineStatus/incidentsOnly?app_id=bd960a5c&app_key=b8b676fb485340bb
1a9352b3d9b44617
connection
keep-alive
content-length
3621
last-modified
Sun, 19 Apr 2015 13:41:29 GMT
server
Microsoft-IIS/7.0
x-request-url
http://cloud.tfl.gov.uk/TrackerNet/lineStatus/incidentsOnly?app_id=bd960a5c&app_key=b8b676fb485340bb
1a9352b3d9b44617
vary
*
data-last-updated
04/19/2015 13:41:04
content-type
text/xml
access-control-allow-origin
*
access-control-expose-headers
cache-control,content-length,content-type,expires,last-modified,vary,server,data-last-updated,x-aspnet-version
,x-powered-by,date,connection,x-final-url,access-control-allow-origin
cache-control
public, max-age=30
expires
Sun, 19 Apr 2015 13:41:59 GMT
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfLineStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org
/2001/XMLSchema" xmlns="http://webservices.lul.co.uk/">
<LineStatus ID="0" StatusDetails="No service between Paddington and Queen's Park while we fix a faulty
train at Warwick Avenue. SEVERE DELAYS on the rest of the line. London Underground tickets will be accepted
on London Overground and local buses.">
<BranchDisruptions>
<BranchDisruption>
<StationTo ID="183" Name="Queen's Park" />
<StationFrom ID="173" Name="Paddington" />
<Status ID="PS" CssClass="DisruptedService" Description="Part Suspended" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</BranchDisruption>
</BranchDisruptions>
<Line ID="1" Name="Bakerloo" />
<Status ID="PS" CssClass="DisruptedService" Description="Part Suspended" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
<LineStatus ID="1" StatusDetails="No service between North Acton and Queensway due to planned engineering
work. GOOD SERVICE on the rest of the line.">
<BranchDisruptions>
<BranchDisruption>
<StationTo ID="185" Name="Queensway" />
<StationFrom ID="157" Name="North Acton" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</BranchDisruption>
</BranchDisruptions>
<Line ID="2" Name="Central" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
<LineStatus ID="5" StatusDetails="No service between Tooting Broadway and Morden due to planned engineering
work. GOOD SERVICE on the rest of the line.">
<BranchDisruptions>
<BranchDisruption>
<StationTo ID="151" Name="Morden" />
<StationFrom ID="232" Name="Tooting Broadway" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</BranchDisruption>
</BranchDisruptions>
<Line ID="5" Name="Northern" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
<LineStatus ID="11" StatusDetails="Train service will resume at 06:15 on Monday.">
<BranchDisruptions />
<Line ID="12" Name="Waterloo and City" />
<Status ID="SC" CssClass="GoodService" Description="Service Closed" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
<LineStatus ID="82" StatusDetails="No service between South Tottenham and Barking due to due to planned
engineering work. GOOD SERVICE on other routes.">
<BranchDisruptions>
<BranchDisruption>
<StationTo ID="14" Name="Barking" />
<StationFrom ID="355" Name="South Tottenham" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</BranchDisruption>
</BranchDisruptions>
<Line ID="82" Name="Overground" />
<Status ID="PC" CssClass="DisruptedService" Description="Part Closure" IsActive="true">
<StatusType ID="1" Description="Line" />
</Status>
</LineStatus>
</ArrayOfLineStatus>
if( 'function' === typeof importScripts) {
importScripts('scripts/polyfill/serviceworker-cache-polyfill.js');
}
var CACHE_NAME = 'london-underground';
// The files we want to cache
var urlsToCache = [
'/',
'css/base.css',
'scripts/map.js',
'scripts/index.js'
];
// Set the callback for the install step
self.addEventListener('install', function (event) {
console.log(event.type);
// Perform install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('activate', function(event) {
console.log('SW activated');
});
self.addEventListener('fetch', function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
// Cache hit - return response
if (response) {
return response;
}
// IMPORTANT: Clone the request. A request is a stream and
// can only be consumed once. Since we are consuming this
// once by cache and once by the browser for fetch, we need
// to clone the response
var fetchRequest = event.request.clone();
return fetch(fetchRequest)
.then(function (response) {
// Check if we received a valid response
if(!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
// IMPORTANT: Clone the response. A response is a stream
// and because we want the browser to consume the response
// as well as the cache consuming the response, we need
// to clone it so we have 2 streams.
var responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(function (cache) {
cache.put(event.request, responseToCache).then(function () {
console.log('successfully cached response!')
});
});
return response;
}
)
})
)
});
So, if I request the XML response above from my page, the service worker is aware of it, makes the request, and is caching other network requests. However, this request, and a similar one to lineStatus.xml, are always being fetched by the serviceworker, leading me to assume that there's something different with these requests.
The only difference I can see is the headers, but I don't know much about headers, as to whether they'd change whether the SW makes them non-cacheable. I've copy-pasted them below
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment