Search code examples
javascriptbrowsermeta-tags

What happens if I change meta tags after the DOM has materialized?


Looking through the A-Frame source, I spot that the library sets several meta tags with JavaScript.

This should be safe in A-Frame's case: Mozilla recommend that their library is imported as a blocking, synchronously loaded script in the <head>, so this work will always happen before we exit <head> parsing.

Still, it got me thinking: what happens if one changes meta tags with JavaScript in an async script, or after DOMContentLoaded?

Some specific questions:

  • is there any guarantee that browsers will respect meta tag mutations?
  • are there known issues with getting a browser to recognise meta tag changes after <head> parsing / DOM materialisation? Will they still 'do things' to the page?
  • are there any other good reasons I shouldn't do this if the meta tags are critical to the job my JavaScript does?

Solution

  • is there any guarantee in the specs that browsers should respect meta tag mutations?

    They are DOM elements, like any other.

    The specs won't mention anything specific because they aren't special cases.

    are there known issues with getting a browser to recognise meta tag changes after <head> parsing / DOM materialisation?

    Not from the POV of examining them in the DOM afterwards.