Created
September 15, 2019 08:08
-
-
Save olegpolyakov/90f7e6d433e43ab2d9c3c1c02ad96283 to your computer and use it in GitHub Desktop.
AJAX Cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const form = document.querySelector('form'); | |
| const input = form.querySelector('input[type="search]"'); | |
| const cache = {}; | |
| form.addEventListener('submit', event => { | |
| event.preventDefault(); | |
| const query = input.value; | |
| if (!cache[query]) { | |
| cache[query] = fetch(`https://google.com?search=${query}`); | |
| } | |
| cache[query] | |
| .then(response => {}) | |
| .catch(error => {}) | |
| .finally(() => {}); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment