Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
API Cache Javascript my caching code doesn't work

i'm working on javascript code and i want to cache http GET request to API Pixabay. Problem the caching doesn't seem to work at all. Datas are always null. I can put a sample of code maybe someone will see something wrong about my code :

if ('caches' in window){
const newCache = await window.caches.open('cache-pixabay');

const options = {
    method: "GET",
    headers: new Headers({
        'Accept': 'application/json',
    }),
  }  

  let request = new Request(URL, options);
  datas = await newCache.match(request);
  alert(JSON.stringify(datas));
if(isEmptyObj(datas)) {
   alert('iciii');
    await newCache.add(request);
    datas = await newCache.match(request);
    alert(JSON.stringify(datas));
}

} else {
    xhttp.open("GET", URL, false);
    xhttp.send();
    datas = JSON.parse(xhttp.responseText);
}

Alert always displays {} null object Response. Need some tips. It lacks of example on internet.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!