diff --git a/dist/assets/index-BeWghAjA.js b/dist/assets/index-BeWghAjA.js new file mode 100644 index 0000000..2d21900 --- /dev/null +++ b/dist/assets/index-BeWghAjA.js @@ -0,0 +1 @@ +(function(){const o=document.createElement("link").relList;if(o&&o.supports&&o.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))s(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const c of n.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&s(c)}).observe(document,{childList:!0,subtree:!0});function r(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerPolicy&&(n.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?n.credentials="include":t.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function s(t){if(t.ep)return;t.ep=!0;const n=r(t);fetch(t.href,n)}})();const l="my-cache-v1",i="https://jsonplaceholder.typicode.com/posts/1",d=document.getElementById("fetch-data"),u=document.getElementById("clear-cache"),a=document.getElementById("output");async function f(){try{if(!navigator.onLine)return!1;const e=new AbortController,o=setTimeout(()=>e.abort(),5e3),r=await fetch("https://jsonplaceholder.typicode.com",{signal:e.signal});return clearTimeout(o),r.ok}catch(e){return console.log("Bağlantı kontrolü hatası:",e),!1}}async function h(){try{const e=await fetch(i);return await(await caches.open(l)).put(i,e.clone()),{data:await e.json(),source:"API"}}catch{throw new Error("Veri API'den alınamadı")}}async function m(){try{const o=await(await caches.open(l)).match(i);return o?{data:await o.json(),source:"Cache"}:null}catch{throw new Error("Cache'den veri alınamadı")}}async function y(){try{a.textContent="Veri getiriliyor...";const e=await m();if(await f()){const{data:r}=await h();a.textContent=`Veri API'den alındı ve önbelleğe kaydedildi: ${JSON.stringify(r)}`,console.log("Veri API'den alındı ve önbelleğe kaydedildi")}else e?(a.textContent=`İnternet bağlantısı yok! Veri önbellekten alındı: ${JSON.stringify(e.data)}`,console.log("Veri önbellekten alındı (offline mod)")):(a.textContent="Veri alınamadı! İnternet bağlantısı yok ve önbellekte veri bulunamadı.",console.log("Veri alınamadı - Bağlantı yok ve önbellek boş"))}catch(e){e instanceof Error&&(a.textContent=`Hata: ${e.message}`,console.error("Hata:",e))}}d.addEventListener("click",y);u.addEventListener("click",async()=>{try{await caches.delete(l),a.textContent="Önbellekteki veri başarıyla silindi!",console.log("Önbellek temizlendi")}catch(e){a.textContent="Önbellekteki veri silinemedi!",console.error("Önbellek temizleme hatası:",e)}}); diff --git a/dist/assets/index-CEzNni47.css b/dist/assets/index-CEzNni47.css new file mode 100644 index 0000000..e45b7ff --- /dev/null +++ b/dist/assets/index-CEzNni47.css @@ -0,0 +1 @@ +body{font-family:Arial,sans-serif;text-align:center;margin-top:50px}button{margin:10px;padding:10px 20px;font-size:16px}#output{margin-top:20px;font-weight:700} diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..7390c52 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,17 @@ + + + + + + Cache API Example + + + + +

JavaScript Cache API ÖrneK

+ + +
+ + + diff --git a/index.html b/index.html index 6376f2c..eb58cb3 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,6 @@

JavaScript Cache API ÖrneK

- + diff --git a/vite.config.ts b/vite.config.ts index e24c9d5..4fc8a11 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,12 @@ import { defineConfig } from "vite"; export default defineConfig({ + base: "/cache_example/", server: { open: true, }, + build: { + outDir: "dist", + assetsDir: "assets", + }, });