Increment in global memory always +2


im try to store increment number in global memory, in preview mode is fine increment +1 but when im check in normal page increment always +2.

please someone help me, and this is sample code:

let thisIsGlobal = 0

addEventListener('fetch', event => {

async function handleRequest(request) {
const response = new Response(thisIsGlobal++)
return response

im get this sample code in Save a token after authentication with external API's? maybe @zack can help me about this issue.

thank you.

Perhaps your browser is doing OPTIONS and GET requests.
Try limiting the response per method

im try to limit request method, but this not solve my issue.
im debug in chrome console, and im getting problem is from favicon access.
browser try to request favicon.ico and this is trigger worker to increment again.

:+1: Solved.
Throw a 404 error for the favicon.

1 Like

for future debuggers:

just debug the requests url also so you know whats happening like:

let requests = [];

async function handleRequest(request) {
// now also debug the requests array to see whats happening, ofcourse dont use it in production