Serving webpages using KV and Worker

Hi, so I am trying to make my website serverless using CF workers and KV. The approach I am using is create a worker that will search the URL in KV namespace and if it’s found return it other wise put the page’s HTML to KV. Before this I tried to cache the HTML by setting Cache-Level to ‘Cache Everything’ but it didn’t go well for me as I was getting my assets cached but the HTML was showing ‘Dynamic’. So I am trying to give KV a try. For the assets(css,js etc) I will use caching. I wanted to know is that a good approach, or can anyone suggest me something? Here is the worker code:

import template from ‘./template’
async function handleRequest(event) {
const request = event.request;
const url = new URL(request.url);

const c = await test.get(${url});

if(!c){
let response = await fetch(request);
response = new Response(response.body, response);
const a = await test.put(${url},response.body);
return new Response(a, {
headers: { ‘content-type’: ‘text/html’ },
})
}else{
return new Response(c, {
headers: { ‘content-type’: ‘text/html’ },
})
}

}
addEventListener(‘fetch’, event => {
try {
return event.respondWith(handleRequest(event));
} catch (e) {
return event.respondWith(new Response('Error thrown ’ + e.message));
}
});

An international, low-latency key-value data storage is called Workers KV. After being accessed, the data is cached in Cloudfare’s data centres from a small number of centralised data centres where it was originally kept.