Skip to content

SEO tags prioritised below style tags #693

Closed

Description

@aethr

Environment

node: v22.22.1

tested on both:
unhead: v3.0.0-beta.12 (main)
unhead: v2.1.12

Reproduction

This test, added to unhead/test/unit/server/tagPriority.test.ts will currently fail:

  it('seo meta above inline style', async () => {
    const head = createServerHeadWithContext()
    head.push({
      style: [{
        textContent: 'body { background: red; }',
      }],
    })
    head.push({
      meta: [
        {
          property: 'og:title',
          content: 'test title',
        },
        {
          name: 'description',
          content: 'desc',
        },
      ],
    })

    const { headTags } = await renderSSRHead(head)
    expect(headTags).toMatchInlineSnapshot(`
      "<meta property="og:title" content="test title">
      <meta name="description" content="desc">
      <style>body { background: red; }</style>"
    `)
  })

Instead, the headTags are rendered in the order they were added:

<style>body { background: red; }</style>
<meta property="og:title" content="test title">
<meta name="description" content="desc">

Describe the bug

Many Open Graph crawlers will only parse the first 1MB of a document (for example, see Meta Web Crawlers documentation) looking for og meta tags. However, nuxt sites often inline <style> tags which can end up being quite large, often exceeding 1MB. When <meta property="og:..."> tags are not rendered before <style> tags in the header, this results in Open Graph previews breaking, and degraded SEO scoring.

Since this module is used by all nuxt sites to provide meta/SEO tags, in my opinion it would be good a good default to place Open Graph and meta tags above style tags by default, preventing this issue.

Additional context

This bug has been reported several times, some of which have been closed, although as far as I can tell the issue has never been resolved:

Automatic tagPriority is assigned to some <meta> tags, but only CSP, charset and viewport meta tags are included. While not as critical, I believe SEO meta tags such as description and Open Graph tags should always be prioritised above inline styles. The performance impact to CSS rendering should be negligible, but the impact for SEO and Open Graph seems like a clear net positive.

I've opened a related issue in nuxt-seo-utils for this in case this change would be too opinionated for unhead.

Edited: some minor corrections and link to nuxt-seo-utils issue.

Activity

  1. added
    bug
    on Mar 13, 2026
  2. aethr commented on Mar 13, 2026

    @aethr
    Author

    It's worth noting that Nuxt UI sets an explicit tagPriority: -2 on colors, fonts and some other inline styles:

    However, I wouldn't expect these styles to grow large enough to impact the discoverability of meta tags that come after them. It's more of an issue when things like tailwind pack a large volume of inline styles into the head, or when inline styles include embedded SVG, etc.

  3. aethr commented on Mar 13, 2026

    @aethr
    Author

    In my case, many Open Graph tags are being set automatically by the nuxt-seo-utils module based on nuxt config. These are set without any explicit tagPriority, and often end up coming after inline styles in my production builds.

    Before updating to unhead v2, I had worked around this issue by explicitly defining some default og tags with tagPriority: 2 in app.vue:

    // duplicate nuxt.config.ts site settings using tagPriority: 2 so that all
    // og tags are rendered above styles
    useSeoMeta({
      ogType: 'website',
      ogSiteName: '...',
      ogUrl: '...',
      ogDescription: '...',
      ogLocale: 'en'
    }, {
      tagPriority: 2,
    })

    I believe because of tag deduplication, this replaced the default meta tags with entries with the same values but lower tagPriority. However, this appears to no longer work with unhead v2.

    For those of us using @nuxtjs/seo or the underlying nuxt-seo-utils, the default Open Graph tags are set via Nuxt config, and there is currently no way to specify tag priority for default meta tags. If it would be more appropriate to fix this issue in one of those modules, I can open an issue there instead.

    I just felt that solving it here in unhead would provide a better default experience for a much larger pool of users.

  4. added a commit that references this issue on Mar 18, 2026
    bef6aba
  5. marked Tag priority Nuxt 4 #590 as a duplicate of this issue on Apr 5, 2026
  6. harlan-zw commented on Apr 5, 2026

    @harlan-zw
    Collaborator

    I appreciate the time taken in investigating this issue, but one of Unhead's values is ensuring the preload scanner can run as quickly as possible. By moving meta tags in front of the style tags, we slow that down.

    While this is mostly negligible, given the scope of the package (8.4M downloads a month), I'd imagine there is a real-world impact on these weights. For example, for ~19 seo tags, we typically delay the preload scanner by ~4.4ms on 3G, which adds up.

    If a site has over 1MB of inline style tags, I'd argue this is an end-user issue. At the framework level, we can change weights depending on whether the request is from a bot. Nuxt SEO Utils will likely do this once it's using Unhead v3. We can also warn the user when they hit this 1MB limit in dev. See #716

    Nuxt UI shouldn't be hardcoding these weights; they should use a relative offset. I'll send a PR for that.

  7. added 2 commits that reference this issue on Apr 5, 2026
    af3ebc6
    9d84180
  8. aethr commented on Apr 7, 2026

    @aethr
    Author

    I agree that this is probably more of a Nuxt framework issue than a library issue. Thanks for the detailed response, it all makes complete sense!

  9. harlan-zw commented on Apr 7, 2026

    @harlan-zw
    Collaborator

    Yes, I'll continue to try and improve this :)

    FWIW, we also mitigate this slightly by minifying any CSS registered through Unhead in v3 using lightningcss if we can process it at build-time, otherwise we fallback to a minimal minifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions