React CDN, First choice for building simple web app?

React CDN, First choice for building simple web app?

posted Originally published at dev.to 2 min read

Using standard Ajax and JQuery CDN for building simple website? ahh..it's so common, how about using CDN for React.js? That sounds interesting, doesn't it?


Using React via a CDN (Content Delivery Network) is a simple way to get started without setting up a full project with tools like Webpack or Vite (especially when you need to build simple and fast landing page). Here’s a prerequisite and a step-by-step guide to using React with a CDN.

Prerequisites

  • Basic knowledge of HTML, JavaScript, and React.
  • A text editor (e.g., VS Code, Sublime, Notepad++).
  • A modern web browser (Chrome, Firefox,
    Edge).
  • An internet connection (since CDNs load resources from the
    web). Step-by-Step Guide to Using React via CDN

Step 1: Create an HTML File.
Open your text editor and create a file named index.html.

Step 2: Add React and ReactDOM via CDN Under the body section of your index.html, add the React and ReactDOM libraries.

!-- React and ReactDOM from CDN -->
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>

<!-- Babel (to use JSX in the browser) -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

Step 3: Adding Components You can define multiple React components inside the script type="text/babel" tag under those React script tags we have defined previously.

<script type="text/babel">
    function Header() {
        return <h2>Welcome to My React App</h2>;
    }

    function App() {
        return (
            <div>
                <Header />
                <p>Welcome fellas..</p>
            </div>
        );
    }

    const root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(<App />);
</script>

This is the full version:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>React with CDN</title>
</head>
<body>
    <div id="root"></div>
</body>

<!-- React and ReactDOM from CDN -->
<script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>

<!-- Babel (to use JSX in the browser) -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>

<!-- Your React Code -->
<script type="text/babel">
    function Header() {
        return <h2>Welcome to My React App</h2>;
    }

    function App() {
        return (
            <div>
                <Header />
                <p>Welcome fellas..</p>
            </div>
        );
    }

    const root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(<App />);
  </script>
</html>

Step 4: Open the HTML File in a Browser Simply double-click the index.html file or open it in a browser and voila! you will see Hello, React with CDN! displayed on the page

So this is the end? I don't think so
What's next?

You can build anything with this React CDN (filtering, scroll-to-top, blurry effect, etc). Just need to relax and get inspirations

Curious what else you can build with this React CDN? Check example of my portfolio page. This page was built using React CDN

source: dev.to

If you read this far, tweet to the author to show them you care. Tweet a Thanks
Although I am not much of a backend engineer, I have seen "React" as a solid framework for software or app development.
Couldn't agree more!
Mikkel , nice guide! I love how simple and fast it is to set up React using a CDN—perfect for quick projects or landing pages without the hassle of complicated build tools.  Do you think this approach is scalable for larger apps, or is it better suited for smaller, simpler projects?
I think it is not powerful enough comparing if you use downloaded package manager (npm) combined with vite, quite faster for development,.

If you're using CDN version, it gathers server sided library and it has a limitation compared using local/downloading version.

But in middle scale app i think it is still good enough

More Posts

Supercharge Your React App and Say Goodbye to Memory Leaks!

Ahammad kabeer - Jun 22, 2024

Why I'm Building My Personal Brand Before Launching My App

Matheo Gomez - Mar 9

Mastering React: A Mindset for Component-Centric Development

Losalini Rokocakau - May 3, 2024

Mastering the Art of Software Engineering & Web Development: The Ultimate Guide for 2024

Hanzla Baig Dev - Feb 24

How Check Memory Leaks in React?

Martins Gouveia - Feb 5
chevron_left