Please add the <noscript> HTML element

I noticed that the <noscript> element is not actually one of the HTML elements in Bootstrap Studio, and when I added this using the custom code element it is not shown.

Please could this be considered to be added in a future update along with being able to enable it or disable it in the design?

1 Like

Thank you for the suggestion! We will investigate adding with the ability to toggle its visibility in the program in one of our next releases.

3 Likes

Woo! I’m glad someone else also mentioned this :grin:
It would be a huge help for accessibility!

1 Like

Hello @martin, is this feature still being considered?

We have it on our list, but we keep adding higher priority items before it. If others would like to see it added do write here so we can give it more attention.

2 Likes

It really would be great addition!

I think it would also be nice if you had a “show / hide” option similar to modals, dropdowns and accordions so the user can make quick edits to it then hide it again. Small pain to disable JavaScript just to see it then accidentally forget you’ve turned it off :sweat_smile:

I also think some web devs forget / don’t know that it exists and don’t think about it when developing their sites.

1 Like

There are alternatives to the <noscript> tag.

Using remove() to Enhance Noscript Fallbacks in JavaScript

When building modern websites, JavaScript plays a crucial role in interactivity and dynamic content. However, not all users have JavaScript enabled, and some search engines or browsers may not fully execute it. That’s where <noscript> and JavaScript fallbacks come into play.

In this post, we’ll explore how to use remove() to efficiently manage fallback elements that appear when JavaScript is disabled, ensuring a seamless user experience.


Why Use JavaScript Fallbacks?

If a website heavily relies on JavaScript to load content, users with JavaScript disabled may see an incomplete or broken page. To address this, we can include fallback elements that provide alternative content. Once JavaScript runs, we can remove these elements to prevent duplication or unnecessary clutter.

Traditional approaches hide fallback elements using CSS (display: none), but a cleaner and more efficient method is to remove them from the DOM entirely using JavaScript’s .remove() method.


Using remove() to Eliminate Fallback Elements

Example 1: Removing an <iframe> Fallback

Suppose your website embeds an iframe to display important content when JavaScript is disabled. We can ensure that this iframe is removed when JavaScript is enabled:

<iframe id="noscript-iframe" src="fallback.html" width="600" height="400">
  Your browser does not support iframes.
</iframe>

<script>
  document.addEventListener("DOMContentLoaded", function () {
    document.getElementById('noscript-iframe')?.remove();
  });
</script>

How It Works

  • If JavaScript is disabled, the iframe remains visible.
  • If JavaScript runs, the <iframe> is removed from the DOM, preventing unnecessary content duplication.

Using the optional chaining operator (?.) ensures that the script doesn’t throw an error if the element doesn’t exist.


Example 2: Removing a <div> Fallback Message

A common practice is to display a warning message when JavaScript is disabled. Instead of just hiding it with CSS, we can completely remove it when JavaScript runs:

<div id="noscript-message">
  <p>JavaScript is disabled. Some features may not work properly.</p>
</div>

<script>
  document.addEventListener("DOMContentLoaded", function () {
    document.getElementById('noscript-message')?.remove();
  });
</script>

Why Use remove() Instead of display: none?

  • Better Performance: Removing elements prevents unnecessary DOM nodes from being processed.
  • Cleaner Markup: Keeps the document structure minimal and reduces HTML bloat.
  • Improved SEO: Search engines may still index hidden elements, but removed elements are ignored entirely.

Best Practices for Using remove()

  1. Ensure the Element Exists Before Removing
    Always check if the element is present to prevent JavaScript errors:

    let element = document.getElementById('noscript-message');
    if (element) element.remove();
    
  2. Use DOMContentLoaded to Wait for DOM Readiness
    Since the script may run before the elements are loaded, use DOMContentLoaded to wait until the page is fully parsed.

  3. Consider Alternative Fallbacks
    If your site requires JavaScript for key functionality, consider providing an HTML-only alternative.


Using remove() is a simple yet powerful way to clean up fallback elements after JavaScript is confirmed to be running. By removing unnecessary elements, we improve both performance and usability, ensuring a better experience for all users.

You will see the “noscript-elements” inside bss

1 Like

So, use JavaScript to remove elements from the DOM if JavaScript is enabled.
If JavaScript is not enabled, the content will remain on the DOM.

I’ll have to try this. At least the content created will be visible on Bootstrap Studio until I hit preview or export.

It can lead to issues since web spiders don’t know how to handle that so could index your site showing that element, especially if they don’t run your sites JS. <noscript> is the standard for a reason.

Googlebot does execute JavaScript, Google hold nearly 80% of the global market share for search engines. This means they process around 3.5 billion searches per day!

Bingbot and Yandex also have limited JavaScript execution capabilities but are not as powerful as Googlebot.

Some SEO crawlers like Screaming Frog (with JavaScript rendering enabled) can also execute JavaScript to analyze dynamic content

Crawlers that DO NOT execute JavaScript (basic search engines, old bots, some SEO tools) will index the site by showing the content inside <noscript>. To prevent unwanted indexing, here is an effective setup.

<head>
  <meta property="og:title" content="My Page Title">
  <meta property="og:description" content="Description for social media previews">
  <meta property="og:image" content="https://example.com/image.jpg">
  <meta property="og:url" content="https://example.com">
  
  <noscript>
    <meta name="robots" content="noindex">
  </noscript>
</head>
<body>
<div id="noscript-message">
  <p>JavaScript is disabled. Please enable it for the best experience.</p>
</div>

<script>
  document.addEventListener("DOMContentLoaded", function () {
    document.getElementById('noscript-message').remove();
  });
</script>
</body>

How it Works:

  1. Crawlers that DO NOT execute JavaScript (basic search engines, old bots, some SEO tools)

    • :white_check_mark: Will respect <noscript><meta name="robots" content="noindex"></noscript> and NOT index the page.
    • :cross_mark: They will NOT index <div id="noscript-message">, because they won’t index the page at all.
    • :white_check_mark: Facebook, Twitter, LinkedIn, etc., will generate a preview because Open Graph (og:) metadata is in <head>.
  2. Crawlers that DO execute JavaScript (Googlebot, Bingbot with JavaScript enabled)

    • :white_check_mark: Will index the page, ignoring <noscript> since JavaScript is running.
    • :white_check_mark: Will NOT index the #noscript-message, because JavaScript removes it before indexing.

Final Behavior:

Crawler Type Executes JS? Indexes Page? Indexes <noscript-message>? Creates Social Media Preview?
Googlebot, Bingbot (with JS) :white_check_mark: Yes :white_check_mark: Yes :cross_mark: No (JS removes it) :cross_mark: No
Basic search crawlers (no JS) :cross_mark: No :cross_mark: No (due to <noscript><meta name="robots" content="noindex"></noscript>) :cross_mark: No (because the page is not indexed) :cross_mark: No
Facebook, Twitter, LinkedIn :cross_mark: No :cross_mark: No (but they don’t rely on search indexing) :cross_mark: No :white_check_mark: Yes (thanks to Open Graph <meta> tags)

Summary:

:white_check_mark: Facebook, Twitter, and LinkedIn will generate a preview using Open Graph (og:) tags.
:white_check_mark: Search engines that execute JavaScript (like Googlebot) will index the page but won’t see the noscript-message.
:white_check_mark: Search engines that do not execute JavaScript (like some SEO crawlers) won’t index the page at all.

This setup effectively prevents unwanted indexing while allowing proper social media previews!

I accept the fact that there are “alternatives” to the <noscript> tag, however you are missing the point that this is a feature request - I am asking for it to be added.

The current work around is to just use the Custom Code block in Bootstrap Studio, which is what I do for my sites that rely on some JS.

While your solution here would work, it’s still not best practice.

  1. <noscript> is the standard, and some accessibility tools rely on finding it.
  2. You don’t need to worry about any compatibility issues since it’s a standard supported feature of all modern browsers.
  3. Using JS to remove a div means your modifying the DOM, this can cause layout shifts which can be unsightly and lowers your sites PageSpeed score.
  4. While most likely negligible, your adding more work for users to load and use your site.
1 Like

I’ve also noticed while testing the JavaScript version to hide elements on the DOM will cause Layout Shifting. While it’s not 100% noticeable, it can still happen. It’s recommended to use <noscript> for best practices. But you can mix them together.

.noscript-message {
    display: none; /* Hide by default */
}
<noscript>
    <style>
    .noscript-message {
        display:block !important; /* Override default to show if no JS */
    }
    </style>
</noscript>

<p class="noscript-message">
    JavaScript is required for this Form to work properly.
</p>
document.addEventListener('DOMContentLoaded', () => {
    document.querySelector('.noscript-message')?.classList.add('hidden');
});
.hidden {
    display: none;
}

Why this is better?

  1. Faster Rendering: CSS hides the message by default, and JavaScript only modifies styles instead of triggering reflows by removing elements.
  2. Avoids Layout Shifts: Removing elements can cause a shift in layout; hiding them prevents that.
  3. Graceful Degradation: If JavaScript fails mid-execution, the message is still accessible.

I also agree that it should be an element within Bootstrap Studio though.
It would make it easier to work with instead of using Custom Code.

I know kuligaposten is just trying to help.

1 Like

@catkin
I did a little more testing and more research on the topic of mixing <noscript> and JavaScript.

<!--
This will allow the message to display when JavaScript is Disabled.
 -->
<noscript>
    <style>
        .noscript-message {
            display: block;
        }
    </style>
</noscript>
/* Hides the message - styles.css */
.noscript-message {
  display: none;
}
<!-- The "noscript" message, hidden using the CSS -->
<div class="mt-2 noscript-message">
    <div class="alert alert-danger small" role="alert">
        <span>
            <strong>
                JavaScript is required to use the navigation.
            </strong>
        </span>
    </div>
</div>
// Since JavaScript loads, we remove the element.
document.addEventListener('DOMContentLoaded', () => {
   document.querySelector('.noscript-message')?.remove(); 
});

@kuligaposten was right on the way to use the JavaScript.
Tweaking it to be a querySelector is better since IDs are meant to be unique and a website might have more than one “noscript-message” on different pages.

In this case, Googlebot and other crawlers will likely not index the .noscript-message content because:

  1. CSS Hides It
  2. JavaScript Removes It
  3. Googlebot Executes JavaScript

when would Google index it?

  • If JavaScript Fails or is Blocked.
  • If CSS or JavaScript are Blocked via robots.txt

This also should not cause Layout Shift because the content is hidden by default.

Could this cause Layout Shift?
Yes, if the .noscript-message was initially visible and then hidden / removed later.

@GregoryAM
have a look at the source code

<script>
        // this runs before the page is visible to the user
        document.querySelectorAll('.noscript-message').forEach(message => message.remove())
    </script>

Include the JavaScript into the body and within <noscript> add:

<meta name="robots" content="noindex">
  1. This should if the user has JavaScript disabled not index the page (if I understood this).
  2. Select ALL .noscript-message classes and remove them on page load before it’s visible to the user (as per your comment).

If I understood this, is that what you wanted me to see?