Workers "Singleton" class


We started using workers for our sites. The purpose of workers on our sites:
mostly inject some code(html/js/css) in different locations of HTML page.
It can be some config data, or some legal text and etc.

So what we do now, is we create a config in KV for each website and based on user country/language. we inject above html/js and etc.

So I have a Store (Singleton pattern), But doesn’t work in workers, by doesn’t work I mean, after first request, the data is persistent, and after some times it get updated, any workaround for this?

Below is some code example.
So this how src/index.js looks like (pseudo code)

import { Store } from "@helpers/store";

addEventListener(‘fetch’, event => {

//HTML Rewriter Class
class Head {

element(el) {
		  	<script id="config">
		  		var config = ${Store.export()};
			</script>`, {
    	html: true


async function handleRequest(request) {
let store = await Store.make(request);

const response = await fetch(request);

let html = new HTMLRewriter();
html.on("head", new Head());

return html.transform(response);



class Store {


	this._request = null
	this._config = {}
	this._url = null


async make(request){

	let config = {}

	this._request = request;

	const domain = this.url.hostname.replace(/http(s)?:\/\/|www\./g, "");

	const country = request.headers.get('cf-ipcountry')

	const website = await WEBSITES.get(domain, "json"); //WEBSITES is KV namespace

	const { license, lang } = website;

	this._config = {

	return this;


	return JSON.stringify(this._config)

get request(){
	return this._request;


get url(){

		this._url = new URL(this.request.url)


	return this._url;



export default new Store()