PWA URL Yönetimi: Progressive Web App SEO Rehberi

Progressive Web App'lerde URL yönetimi, Service Worker routing ve deep linking stratejilerini öğrenin. PWA SEO optimizasyonu rehberi.

Progressive Web App'ler (PWA), web teknolojileri kullanarak native uygulama benzeri deneyimler sunar. Bu rehberde, PWA'larda URL yönetimi ve SEO stratejilerini detaylı olarak inceleyeceğiz.

PWA URL Yapısı

Single Page Application (SPA) URL'leri

// Hash-based routing (eski yöntem)
https://example.com/#/sayfa
https://example.com/#/urunler/kategori

// History API routing (önerilen)
https://example.com/sayfa
https://example.com/urunler/kategori

// Clean URL'ler SEO için daha iyi

Web App Manifest URL'leri

// manifest.json
{
  "name": "Uygulama Adı",
  "short_name": "App",
  "start_url": "/",
  "scope": "/",
  "display": "standalone",
  "icons": [...]
}

// start_url: Uygulama açıldığında yüklenecek URL
// scope: PWA'nın kontrol ettiği URL aralığı

Service Worker ve URL Routing

Service Worker Kaydı

// Service Worker registration
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw.js', {
    scope: '/'
  }).then(registration => {
    console.log('SW registered:', registration.scope);
  });
}

// scope parametresi URL kapsamını belirler

URL Caching Stratejileri

// sw.js - Cache First stratejisi
self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request)
      .then(response => {
        if (response) {
          return response; // Cache'den döndür
        }
        return fetch(event.request); // Network'ten al
      })
  );
});

// URL pattern'lerine göre farklı stratejiler
// - Cache First: Statik assets
// - Network First: API calls
// - Stale While Revalidate: Sık güncellenen içerik

Deep Linking

Universal Links / App Links

// iOS Universal Links
// apple-app-site-association dosyası
{
  "applinks": {
    "apps": [],
    "details": [{
      "appID": "TEAM_ID.com.example.app",
      "paths": ["/urunler/*", "/blog/*"]
    }]
  }
}

// Android App Links
// assetlinks.json dosyası
[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.example.app",
    "sha256_cert_fingerprints": ["..."]
  }
}]

PWA Deep Link Handling

// URL'den state'i okuma
const url = new URL(window.location.href);
const path = url.pathname;
const params = url.searchParams;

// Router ile deep link handling
const routes = {
  '/': HomePage,
  '/urunler/:id': ProductPage,
  '/kategori/:slug': CategoryPage
};

// Paylaşılabilir URL'ler oluşturma
function shareProduct(productId) {
  const shareUrl = `https://example.com/urunler/${productId}`;
  navigator.share({ url: shareUrl });
}

PWA SEO Optimizasyonu

Server-Side Rendering (SSR)

// SSR ile SEO dostu PWA
// Next.js örneği
export async function getServerSideProps(context) {
  const { slug } = context.params;
  const product = await fetchProduct(slug);
  
  return {
    props: { product }
  };
}

// URL: /urunler/[slug]
// Her sayfa için benzersiz HTML

Prerendering

// Prerender.io veya Rendertron ile
// Bot trafiği için önceden render edilmiş sayfalar

// User-Agent kontrolü
if (isBot(userAgent)) {
  // Prerendered HTML döndür
  return prerenderResponse;
} else {
  // Normal SPA döndür
  return spaResponse;
}

URL State Management

History API Kullanımı

// Sayfa geçişlerinde URL güncelleme
function navigateTo(path) {
  history.pushState({ page: path }, '', path);
  renderPage(path);
}

// Geri/ileri butonları için
window.addEventListener('popstate', (event) => {
  const path = window.location.pathname;
  renderPage(path);
});

// URL'i değiştirmeden state güncelleme
history.replaceState({ page: 'updated' }, '', '/ayni-url');

Query Parameters

// Filter ve sort için URL parametreleri
https://example.com/urunler?kategori=elektronik&siralama=fiyat&sayfa=2

// URLSearchParams ile işlem
const params = new URLSearchParams(window.location.search);
const kategori = params.get('kategori');
const siralama = params.get('siralama');

// Parametreleri güncelleme
params.set('sayfa', '3');
history.pushState({}, '', `?${params.toString()}`);

Offline URL Handling

Offline Fallback Sayfası

// sw.js - Offline fallback
self.addEventListener('fetch', event => {
  event.respondWith(
    fetch(event.request)
      .catch(() => {
        // Offline ise fallback sayfası göster
        return caches.match('/offline.html');
      })
  );
});

// Offline.html
// - Önbelleğe alınmış içerik listesi
// - Yeniden bağlanınca senkronizasyon

PWA URL Best Practices

Framework Örnekleri

React Router

// BrowserRouter ile clean URL'ler
import { BrowserRouter, Route, Routes } from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/urunler/:id" element={<Product />} />
      </Routes>
    </BrowserRouter>
  );
}

Vue Router

// Vue Router history mode
const router = createRouter({
  history: createWebHistory(),
  routes: [
    { path: '/', component: Home },
    { path: '/urunler/:id', component: Product }
  ]
});

Sonuç

PWA'larda doğru URL yönetimi hem kullanıcı deneyimi hem de SEO için kritik öneme sahiptir. Clean URL'ler, proper routing ve SSR kombinasyonu ile hem hızlı hem de arama motorları tarafından indekslenebilir PWA'lar oluşturabilirsiniz.