Charlotte Tan
Charlotte Tan

Reputation: 2552

MeteorJS - Fallback for disabled javascript?

What's the best way to handle browsers that have javascript turned off (or if the script doesn't load for some reason)? I know less than 5% of people do that these days, but I'd still like to have some sort of fallback if possible.

Upvotes: 4

Views: 249

Answers (1)

Abdul Rahman Mohsen
Abdul Rahman Mohsen

Reputation: 115

First approach:

You can use a body class:

See the Meteor website's example or:

<head>
    <title>My Title</title>
    <style>
        body{
            background-image: url('http://www.images.com/bgimg.jpg');
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: center;
        }

        .has-script{
            background-image: none;
        }
    </style>
</head>

<body class="has-script">
<h1>Welcome to our website!</h1>

{{> hello}}

body:not(.has-script) {
      margin-top: 100px;
      text-align: center;
      font-size: 20px;

      &::before {
        content: "Please enable JavaScript!";
      }
    }

Second Approach:

You can save a cached version for the produced HTML templates, and serve them from there.

You can add a cache manifest to a Meteor app like manifestR

Though I don't know how complex your templates are..

Third Approach and the best one:

Basicly on the browser side, add the noscript code to the head

<noscript>
    <style>
        body {
            font-size: 32px;
            text-align: center;
            line-height: 100vh;
        }
        body:after {
            content: "Please enable JavaScript in your browser to view this site.";
        }
    </style>
</noscript> 

Upvotes: 3

Related Questions