<p>The simplest way to update the title is to include a title element anywhere in the response.</p>
<pre><code>&lt;title&gt;New title&lt;/title&gt;
</code></pre>
<p>I’m not sure if the same is true for meta tags. You can ask I in the <a href="https://htmx.org/discord" rel="nofollow noreferrer">htmx discord server</a>, since swap functionality is handled by htmx.</p>

CC BY-SA 4.0
2024-10-15T19:55:37.273Z
Works great! Thanks! I thought just tags with an id would get replaced.
Matthias Redl-Mann
CC BY-SA 4.0
2024-10-15T09:38:05.583Z
2024-10-15T14:51:26.133Z
2024-10-15T14:51:26.133Z
Ben Croker
<p>We are currently working on a website using the Sprig Plugin to show and reactively filter event overviews.</p>
<p>One of the options is to browse through monthly views, showing you all information for one month at a time. In this context we also update the URL the <code>s-push-url</code> attribute and we also want to update <code>&lt;title&gt;</code> and maybe some meta tags.</p>
<p>Our way to do it is by listening to the htmx:afterOnLoad event and fetching title information from a certain header:</p>
<pre><code>&lt;script&gt;
    document.body.addEventListener('htmx:afterOnLoad', function(event) {
        // Check if the response includes a custom header or data with the new title
        var newTitle = event.detail.xhr.getResponseHeader('X-Page-Title');
        if (newTitle) {
            document.title = newTitle;
        }
    });
&lt;/script&gt;
</code></pre>
<p>This works but I do not really like it. Are there any other solutions for this requirement?</p>
<p>Thanks!</p>

<meta><sprig><head>
SPRIG: best way to update head information like title, meta,
# SPRIG: best way to update head information like title, meta,

(Asked by: username_0 on 2024-10-15)

We are currently working on a website using the Sprig Plugin to show and reactively filter event overviews.
One of the options is to browse through monthly views, showing you all information for one month at a time. In this context we also update the URL the s-push-url attribute and we also want to update  and maybe some meta tags.
Our way to do it is by listening to the htmx:afterOnLoad event and fetching title information from a certain header:


This works but I do not really like it. Are there any other solutions for this requirement?
Thanks!

**Tags:** meta, sprig, head

---

## 1 answers

### Answer by username_1 on 2024-10-15. Score: 2 | Accepted answer

The simplest way to update the title is to include a title element anywhere in the response.
New title

I’m not sure if the same is true for meta tags. You can ask I in the htmx discord server, since swap functionality is handled by htmx.

> **Comments:**
> **username_0**: Works great! Thanks! I thought just tags with an id would get replaced.  

---

