Skip to content

Commit 669abd4

Browse files
committed
Load index.json from the CDN instead of copying it to the app origin
The service worker precache and the runtime index loader used a same-origin /docs path for index.json, on the assumption that the cache couldn't hold the CDN's CORS responses. That assumption dates to the applicationCache era (2013) and is false for service workers, which cache CORS responses fine; documents.devdocs.io already serves index.json with access-control-allow-origin. Point both doc_index_urls (SW precache) and Doc#indexUrl at docs_origin so they load index.json straight from the CDN, and drop the now-dead index_host special-case and index_path config. prepare_deploy no longer needs to copy index.json into the app's public/docs, so stop downloading it — restoring the deploy-size/timeout win from 45867a2 without breaking the service worker. See #2686.
1 parent 049ce0c commit 669abd4

5 files changed

Lines changed: 8 additions & 21 deletions

File tree

assets/javascripts/app/app.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,6 @@ class App extends Events {
282282
document.documentElement.classList.remove("_booting");
283283
}
284284

285-
indexHost() {
286-
// Can't load the index files from the host/CDN when service worker is
287-
// enabled because it doesn't support caching URLs that use CORS.
288-
return this.config[
289-
this.serviceWorker && this.settings.hasDocs()
290-
? "index_path"
291-
: "docs_origin"
292-
];
293-
}
294-
295285
onBootError(...args) {
296286
this.trigger("bootError");
297287
this.hideLoadingScreen();

assets/javascripts/app/config.js.erb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ app.config = {
66
env: '<%= App.environment %>',
77
history_cache_size: 10,
88
index_filename: 'index.json',
9-
index_path: '/<%= App.docs_prefix %>',
109
max_results: 50,
1110
production_host: 'devdocs.io',
1211
search_param: 'q',

assets/javascripts/models/doc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ app.models.Doc = class Doc extends app.Model {
5151
}
5252

5353
indexUrl() {
54-
return `${app.indexHost()}/${this.slug}/${app.config.index_filename}?${
55-
this.mtime
56-
}`;
54+
return `${app.config.docs_origin}/${this.slug}/${
55+
app.config.index_filename
56+
}?${this.mtime}`;
5757
}
5858

5959
toEntry() {

lib/app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def user_has_docs?(slug)
181181
def doc_index_urls
182182
docs.each_with_object [] do |slug, result|
183183
if doc = settings.docs[slug]
184-
result << File.join('', settings.docs_prefix, slug, 'index.json') + "?#{doc['mtime']}"
184+
result << "#{settings.docs_origin}/#{slug}/index.json?#{doc['mtime']}"
185185
end
186186
end
187187
end

lib/tasks/docs.thor

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,10 @@ class DocsCLI < Thor
249249
dir = File.join(Docs.store_path, doc.path)
250250
FileUtils.mkpath(dir)
251251

252-
# meta.json is needed to build the manifest. index.json must also be
253-
# copied to the app's own origin: when the service worker is enabled
254-
# (the production default) clients load index.json from same-origin
255-
# /docs rather than the CDN, because the service worker can't cache
256-
# the CDN's CORS responses (see App#indexHost / app.js).
257-
['index.json', 'meta.json'].each do |filename|
252+
# Only meta.json is needed to build the manifest; clients (and the
253+
# service worker precache) load index.json directly from the CDN,
254+
# which serves it with CORS headers.
255+
['meta.json'].each do |filename|
258256
json = "https://documents.devdocs.io/#{doc.path}/#{filename}?#{time}"
259257
begin
260258
attempts = 0

0 commit comments

Comments
 (0)