Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
gatsby-plugin-js-fallback
Advanced tools
Gatsby plugin to fallback gracefully when JS is disabled on client side
Gatsby plugin to fallback gracefully when JS is disabled on client side.
// In your gatsby-config.js
module.exports = {
plugins: [
`gatsby-plugin-js-fallback`
// ... other plugins
]
};
Then in the React components/page that you would like to provide a fallback when JavaScript is disabled on client side:
import React from 'react';
import { useIsJsEnabled } from 'gatsby-plugin-js-fallback';
const GracefulPage = () => {
const isJsEnabled = useIsJsEnabled();
return isJsEnabled ? <MyFancyComponentThatNeedJs /> : <SimpleComponent />;
};
useIsJsEnabled
would returns false
, thus the pre-rendered HTML will contain the fallback UI that does not rely on JavaScript.useIsJsEnabled
would returns true
, then the UI that relies on JavaScript will be displayed.useIsJsEnabled
A custom hooks that only returns true
when your Gatsby site hydrate successfully on client side.
Sometimes, you want to introduce some components in your Gatsby site that rely heavily on JavaScript. However, this would cause your site non-usable when JavaScript is disabled on client side.
There are two approaches to deal with this:
This plugin allows you to implement second approach.
There may be content flash from the fallback UI to the enhanced UI at initial page/page refresh. This is because the pre-rendered HTML (that contains the fallback UI) will be displayed while the page is downloading all the js files and then detect if JS is enabled.
There is no solution to avoid this content flash at the moment. If you have any suggestion, raise an issue at let me know!
FAQs
Gatsby plugin to fallback gracefully when JS is disabled on client side
We found that gatsby-plugin-js-fallback demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.