Documentation Shento Hendriks
Svelte / SvelteKit
Svelte / SvelteKit
  • Getting Started with SvelteKit
    • Installing SvelteKit
      • Tailwind Typography plugin
    • Base Syntax & Core Features of Svelte
      • Curly Braces & Understanding Core Syntax
      • Reactive Variables
      • Two-way-binding Shortcut
      • Using multiple components
      • Components & Communication via Props
      • Display HTML in Svelte
      • Dynamic classes
      • Using $effect
      • Working with Javascript and Rune reactivity
    • Working with Conditionals & Loops
      • Showing code conditionally in Svelte
      • Looping through arrays (lists)
      • Lists & Keys
    • Closer look at reactivity
      • Updating Arrays & Objects
      • Event Modifiers
    • Component Events
    • Best Practices
    • Adding Google Font in Tailwind and SvelteKit
    • Adding Local Fonts to SvelteKit with Tailwind
    • Prevent flicker in images
    • Enhanced Images
    • Form Submissions in SvelteKit
    • Effective SEO in SvelteKit
    • Automatic Site Maps in Svelte
    • Creating Custom Elements with Svelte, SvelteKit, and Vite
    • Creating a Svelte Library with JavaScript Functions
  • Useful Code Snippets
    • Hover effects
    • Navigation
    • Centering Items
    • Setting Footer Bottom Page
  • Installing Useful Libraries
    • Documenting Javascript with JSDocs (Crash Course)
    • Adding Lottie Animations to Svelte Application
    • SvelteKit Melt-ui
      • First Component - accordion
    • Installing Shadcn/ui Svelte
    • Getting Started with GSAP with SvelteKit
      • What is GSAP?
      • Installing GSAP & Your first animation
      • GSAP in SvelteKit
    • Installing Locomotive Scroll with Svelte 5 and SvelteKit
  • SvelteKit Server Fetching and Deployment
    • Preparing a SvelteKit application for Deployment
    • Utility Functions for URL Handling in SvelteKit
    • Fetching Directus Data from Rest API with SvelteKit
    • Fetching data from api with caching
    • Displaying Fetched Data in a Each Loop
    • Creating slug friendly urls based on query data
    • Finding correct query in api based on url slug
Powered by GitBook
On this page
  • Step 1: Create an SEO Component
  • Step 2: Use the SEO Component in Your Pages
  1. Getting Started with SvelteKit

Effective SEO in SvelteKit

To make your SEO scalable in SvelteKit, you can create a reusable SEO component that automatically populates the meta tags based on the provided data. This way, you only need to specify the SEO-related information (like title, description, etc.) for each page, and the SEO component will handle the rest. Here's how you can achieve this:

Step 1: Create an SEO Component

Create a reusable SEO component inside the $lib directory that accepts the necessary data as props and renders the appropriate meta tags in the <svelte:head>.

<!-- src/lib/components/SEO.svelte -->
<script>
	import { page } from '$app/stores';

	const {
		title = 'My SvelteKit App',
		description = 'My SvelteKit App',
		image = 'https://example.com/image.jpg'
	} = $props();

	let url = $derived($page.url.href);
</script>

<svelte:head>
	<title>{title || defaultTitle}</title>
	<meta name="description" content={description} />
	<meta property="og:title" content={title} />
	<meta property="og:description" content={description} />
	<meta property="og:image" content={image} />
	<meta property="og:url" content={url} />
	<meta name="twitter:card" content="summary_large_image" />
	<meta name="twitter:title" content={title} />
	<meta name="twitter:description" content={description} />
	<meta name="twitter:image" content={image} />
</svelte:head>

Step 2: Use the SEO Component in Your Pages

In your individual pages or components, import the SEO component from $lib and pass the necessary data as props.

<!-- src/routes/about/+page.svelte -->
<script>
  import SEO from '$lib/components/SEO.svelte';

  const title = 'About Us -- Our Company';
  const description = 'Learn more about our company and mission.';
  const image = 'Image here';
</script>

<SEO {title} {description} />

<h1>{title}</h1>
<p>Welcome to our about page!</p>

In your <head> title use pipes | to use space. Your page's main target keyword should appear in the title tag, ideally towards the beginning. If you want to include your site or brand name, place it at the end of the title after a separator. The main keywords should come first.

PreviousForm Submissions in SvelteKitNextAutomatic Site Maps in Svelte

Last updated 9 months ago