Skip to content

Commit

Permalink
Add prefetch and deepfetching to PDP
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrorojasg committed May 28, 2021
1 parent 3b84444 commit 36f76e5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Assignment:
First, I implemented steps 1-11.

Then, I understand how the code works.

Then, I added a prefetch route to '/p/:path*' (routes.ts).

To improve performance, I decided to implement Deepfetching to PDP. So, I added to service-workers.ts the CSS image selectors of PDP page (.primary-image, .productthumbnail, .lazyloaded).

I could verify how in the collection pages, the prefetch and deepfetching started working as expected.


Next steps:
I would like to implement deepfetching for PDP styling sheets.
I would like to do more tests to could optimize the configuration.


+++++++++++++++++
# Layer0 Traditional Template

The repository for the layer0 Traditional template.
Expand Down
1 change: 1 addition & 0 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default new Router()
.match('/', shoppingFlowRouteHandler)
.match('/home', shoppingFlowRouteHandler)
.match('/c/:path*', shoppingFlowRouteHandler)
.match('/p/:path*', shoppingFlowRouteHandler)
.match('/service-worker.js', ({ serviceWorker }) => serviceWorker('dist/service-worker.js'))
.match('/main.js', ({ serveStatic, cache }) => {
cache(CACHE_ASSETS)
Expand Down
22 changes: 22 additions & 0 deletions src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ new Prefetcher({
as: 'image',
callback: deepFetchPLPHero
},
{ /* PDP image */
selector: '.primary-image',
maxMatches: 1,
attribute: 'src',
as: 'image',
callback: deepFetchPDPImages
},
{ /* PDP image */
selector: '.productthumbnail',
maxMatches: 1,
attribute: 'src',
as: 'image',
callback: deepFetchPDPImages
},
{ /* PDP image */
selector: '.lazyloaded',
maxMatches: 1,
attribute: 'src',
as: 'image',
callback: deepFetchPDPImages
}
]),
],
})
Expand All @@ -29,6 +50,7 @@ new Prefetcher({

function deepFetchPDPImages({ $el, el, $ }: DeepFetchCallbackParam) {
const url = $el.attr('src')
prefetch(url, 'image')
}

function deepFetchPLPHero({ $el, el, $ }: DeepFetchCallbackParam) {
Expand Down

0 comments on commit 36f76e5

Please sign in to comment.