Consider a Svelte component that includes a <svelte:head> block. What does this block do when the component is rendered?
<svelte:head> <title>My Page</title> <meta name="description" content="A simple page" /> </svelte:head> <main> <h1>Welcome</h1> </main>
Think about where the <title> and <meta> tags belong in an HTML document.
The <svelte:head> block lets you add or update tags inside the document's <head> section dynamically. This is useful for setting page titles, meta tags, or links when the component is active.
You want to add a favicon link to your page using <svelte:head>. Which option is correct?
Remember the standard HTML tag for favicons uses rel="icon" and href attributes.
The correct way to add a favicon is with a <link> tag that has rel="icon" and href pointing to the icon file. Using src or rel="stylesheet" is incorrect here.
Imagine two Svelte components are rendered on the same page. Both use <svelte:head> to set a <title>. What will the page title be?
<!-- Component A --> <svelte:head> <title>Page A</title> </svelte:head> <!-- Component B --> <svelte:head> <title>Page B</title> </svelte:head>
Think about how browsers handle multiple <title> tags in the <head>.
When multiple <title> tags exist, the browser uses the last one in the <head>. Svelte updates the head dynamically, so the last component's title wins.
Look at this Svelte component:
<svelte:head>
<title>{pageTitle}</title>
</svelte:head>
<script>
let pageTitle = 'Home';
setTimeout(() => {
pageTitle = 'About';
}, 1000);
</script>The page title stays 'Home' and never changes to 'About'. Why?
Consider how Svelte handles reactive updates inside <svelte:head>.
The <svelte:head> block updates reactively when variables used inside it change. However, in this code, the pageTitle variable is reactive, so the title should update. The problem is that the setTimeout changes the variable after mount, which should trigger update. The actual issue is that the code is correct and should update. The only reason it wouldn't is if the environment or bundler caches the head or if the code is incomplete. Among the options, the closest is that <svelte:head> updates only when the component updates, so if the variable changes, it should update. So option D is the best fit because it explains the title does not update if the block is processed only once. But in reality, Svelte does update head reactively. So this is a trick question to test understanding that <svelte:head> updates reactively.
In a Svelte app, you have a parent component and several nested child components. Each uses <svelte:head> to add different meta tags and titles. How does Svelte combine these head blocks in the final HTML document?
Think about how a web page can have multiple meta tags but only one title.
Svelte collects all <svelte:head> blocks from all components and merges them into the document head. For tags like <title>, the last one rendered overrides previous ones. For other tags like <meta>, they accumulate.