Answer the question
In order to leave comments, you need to log in
How to cache data?
There is a form with a drop-down list, which is filled from an external service. How to implement data caching in order to:
1) If the cache file (arbitrary format, for example text) is missing, make a request to the service and save the result to a file.
2) If the cache file is present and the last date of its modification was today, then get the list of cities from the file.
3) If the file exists, but the modification date is not today, then re-request the list of cities from the service and save it to a file.
With what help it is necessary to implement js or php? Where to start?
function init() {
let url = "http://exercise.develop.maximaster.ru/service/city/";
fetch(url)
.then((response) => {
return response.json();
})
.then((data) => {
data.forEach((item) => {
let option = document.createElement("option");
option.innerHTML = item;
option.setAttribute("name", "option");
selected.appendChild(option);
});
});
}
init();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question