Skip to content

Commit

Permalink
Fetch resources the same way in enqueue to getResourcesForPathname
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bailey committed Nov 15, 2018
1 parent fbeee6d commit 0d0b001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 62 deletions.
23 changes: 9 additions & 14 deletions packages/gatsby/cache-dir/loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pageFinderFactory from "./find-page"
import emitter from "./emitter"
import prefetchHelper from "./prefetch"

const preferDefault = m => (m && m.default) || m

Expand Down Expand Up @@ -106,15 +105,6 @@ const fetchResource = resourceName => {
})
}

const prefetchResource = resourceName => {
if (resourceName.slice(0, 12) === `component---`) {
createComponentUrls(resourceName).forEach(url => prefetchHelper(url))
} else {
const url = createJsonURL(jsonDataPaths[resourceName])
prefetchHelper(url)
}
}

const getResourceModule = resourceName =>
fetchResource(resourceName).then(preferDefault)

Expand Down Expand Up @@ -227,10 +217,15 @@ const queue = {
}

// Prefetch resources.
if (process.env.NODE_ENV === `production`) {
prefetchResource(page.jsonName)
prefetchResource(page.componentChunkName)
}
Promise.all([
getResourceModule(page.componentChunkName),
getResourceModule(page.jsonName),
]).then(([component, json]) => {
if (component && json) {
// Tell plugins the path has been successfully prefetched
onPostPrefetchPathname(path)
}
})

return true
},
Expand Down
48 changes: 0 additions & 48 deletions packages/gatsby/cache-dir/prefetch.js

This file was deleted.

0 comments on commit 0d0b001

Please sign in to comment.