-Dev build
-Local Server
-HMR
-File watching algo
-Caching
-Image optimization
-File compression
-Bundling
-Consistent Hashing
-Code splitting
-Differential bundling
# React Basics – Important Concepts
This README contains important React and frontend concepts explained in simple language with examples.
- What is Emmet?
- Library vs Framework
- What is a CDN?
- Why is React called React?
- What is crossorigin in the script tag?
- React vs ReactDOM
- react.development.js vs react.production.js
- Quick Revision
Emmet is a toolkit built into code editors like VS Code that helps us write HTML and CSS faster using short abbreviations.
Instead of writing:
<div class="container">
<h1>Hello</h1>
<p>Welcome</p>
</div>We can write:
div.container>h1{Hello}+p{Welcome}
Then press Tab, and Emmet expands it into the complete HTML.
| Emmet | Output |
|---|---|
! |
HTML5 boilerplate |
div |
<div></div> |
p |
<p></p> |
.container |
<div class="container"></div> |
#header |
<div id="header"></div> |
ul>li*3 |
<ul> containing 3 <li> elements |
h1{Hello} |
<h1>Hello</h1> |
Emmet saves time by allowing developers to generate repetitive HTML/CSS code using short abbreviations.
The easiest way to remember the difference:
Library → You call it when you need it.
Framework → It calls your code when it needs it.
A library is a collection of ready-made functionality that we can use in our application whenever we need it.
React mainly helps us build the UI of our application.
function App() {
return <h1>Hello World</h1>;
}React does not force us to use a particular solution for everything else.
We can choose different tools for different requirements:
React → UI
React Router → Routing
Axios → API calls
Redux → State management
Node/Express → Backend
MongoDB → Database
So, we control the application and choose the tools we need.
A framework provides a larger structure for building an application.
For example, Angular provides built-in solutions for:
Angular
├── Components
├── Routing
├── Forms
├── HTTP requests
├── Dependency Injection
└── Project structure
The framework provides more rules and structure for how the application should be built.
| React | Angular |
|---|---|
| Library | Framework |
| Mainly focuses on UI | Provides a complete application structure |
| More flexible | More opinionated |
| Additional tools can be chosen | Many tools are built in |
| Developer has more control | Framework controls more of the application flow |
React is mainly focused on the UI layer.
It does not force developers to use a specific solution for:
- Routing
- State management
- API calls
- Form handling
- Backend
Developers can choose the tools they want.
Therefore, React is generally referred to as a library rather than a complete framework.
A library provides specific functionality that we can use whenever we need it, while a framework provides the overall structure and controls the flow of the application. React is called a library because it mainly focuses on building the UI and allows developers to choose other tools for the rest of the application.
CDN stands for Content Delivery Network.
A CDN is a network of servers distributed across different locations that delivers files such as:
- JavaScript
- CSS
- Images
- Videos
- Fonts
A CDN link is simply a URL pointing to a file hosted on a CDN.
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>Here, React is being loaded from a CDN.
Suppose our server is located in India and a user is accessing the website from the USA.
USA User
|
v
Your Server (India)
|
v
JavaScript File
The request has to travel a long distance.
USA User
|
v
Nearby CDN Server
|
v
JavaScript File
The file can be delivered from a server geographically closer to the user.
Files can be served from a server closer to the user.
Static files can be served by the CDN instead of our own server.
CDNs have multiple servers, so resources can remain available even if one server has an issue.
Libraries such as React, Bootstrap, jQuery, etc. can be loaded using a simple URL.
CDN is a network of geographically distributed servers that delivers static resources to users efficiently and quickly.
React is called React because the UI reacts to changes in data or state.
For example:
function App() {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>{count}</button>;
}When the user clicks the button:
count = 0
|
v
User clicks button
|
v
count = 1
|
v
React reacts to the change
|
v
UI gets updated
We don't manually find the button and change its text.
React detects the state change and updates the necessary part of the UI.
React is called React because the UI reacts to changes in application data or state. When the state changes, React efficiently updates the affected parts of the UI.
The crossorigin attribute tells the browser how to handle a cross-origin request when loading a resource such as a script.
<script src="https://cdn.example.com/app.js" crossorigin="anonymous"></script>Suppose our website is:
mywebsite.com
and the script is hosted at:
cdn.example.com
These are different origins, so this is a cross-origin request.
<script src="https://cdn.example.com/app.js" crossorigin="anonymous"></script>The browser makes the cross-origin request without including user credentials such as cookies.
This is commonly used for public resources hosted on CDNs.
For example, if React is publicly available on a CDN, the server doesn't need to know who we are.
Browser
|
| Request without credentials
v
CDN
|
v
Public React File
<script src="https://example.com/app.js" crossorigin="use-credentials"></script>This allows credentials such as cookies to be included in the cross-origin request.
For example:
Browser
|
| Cookie: sessionId=ABC123
v
Server
The server can use the cookie to identify the user's session.
anonymous |
use-credentials |
|---|---|
| Credentials are not sent | Credentials can be sent |
| Cookies are not included | Cookies can be included |
| Common for public CDN resources | Used when authentication/credentials are required |
| Server doesn't receive user credentials | Server can use credentials to identify the session |
anonymous does not mean that the server cannot respond.
It simply means that the browser doesn't send credentials such as cookies with that cross-origin request.
If the resource is public, the server can simply return it.
Also, crossorigin does not itself decide whether the server allows access.
CORS and the server's configuration determine what cross-origin requests are allowed.
anonymous
↓
No credentials
↓
Access public resource
use-credentials
↓
Credentials can be sent
↓
Server can identify the session
The easiest way to remember:
React → Creates/defines the UI
ReactDOM → Renders that UI into the browser DOM
React is the core library used to create UI components.
Example:
function App() {
return <h1>Hello World</h1>;
}React handles concepts such as:
- Components
- JSX
- State
- Props
- Reconciliation
ReactDOM connects React with the browser DOM.
Example:
import ReactDOM from "react-dom/client";
ReactDOM.createRoot(document.getElementById("root")).render(<App />);Here:
<App />
|
v
React
|
v
ReactDOM
|
v
Browser DOM
|
v
<div id="root"></div>
ReactDOM acts as the renderer that connects React with the browser.
React can work with different environments.
React
├── ReactDOM → Web browser
├── React Native → Mobile applications
└── Other Renderers → Other environments
The React core handles UI logic, while the renderer handles how that UI is displayed in a particular environment.
React is the core library used to build UI components, while ReactDOM is the renderer that connects React with the browser's DOM.
Both files contain React, but they are designed for different environments.
Development → For developers
Production → For real users
This version is used while developing the application.
It provides additional:
- Warnings
- Error messages
- Development checks
- Debugging information
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>The development build is generally larger because it contains additional development-related checks and information.
This version is used when the application is deployed for users.
It is optimized for production and removes/reduces development-only overhead.
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>The production build is:
- Smaller
- Optimized
- Faster for end users
- Free from many development-only warnings/checks
| Development | Production |
|---|---|
react.development.js |
react.production.js |
| Used during development | Used after deployment |
| More detailed warnings | Fewer development warnings |
| More debugging information | Less debugging information |
| Larger | Smaller |
| Development checks enabled | Development overhead removed/reduced |
react.development.jsis designed for development and includes additional warnings and checks to help developers debug their applications.react.production.jsis optimized for production and removes development overhead to improve performance.
| Concept | Simple Meaning |
|---|---|
| Emmet | Write HTML/CSS faster using abbreviations |
| Library | You call it when you need it |
| Framework | Provides structure and controls application flow |
| React | UI library |
| CDN | Network of servers that delivers files efficiently |
crossorigin |
Controls how cross-origin resources are requested |
anonymous |
Cross-origin request without credentials |
use-credentials |
Cross-origin request can include credentials |
| ReactDOM | Connects React with the browser DOM |
| Development build | Used while developing |
| Production build | Optimized for deployed applications |
Emmet
↓
Write code faster
Library
↓
You control when to use it
Framework
↓
Provides structure and controls application flow
CDN
↓
Delivers static files from distributed servers
React
↓
UI Library
ReactDOM
↓
Connects React with Browser DOM
crossorigin
↓
Controls cross-origin resource requests
anonymous
↓
No credentials
use-credentials
↓
Credentials can be included
Development Build
↓
Debugging + warnings
Production Build
↓
Optimized for users
- What is NPM?
- What are Parcel / Webpack?
- What is
.parcel-cache? - What happens if
.parcel-cachedoesn't exist? - What is
npx? - Dependencies vs
devDependencies - What is the
distfolder? distvs.parcel-cache- What is Browserslist?
NPM (Node Package Manager) is a tool used with Node.js to install and manage packages (libraries) for your project.
Think of NPM like an app store for JavaScript packages 📦.
For example:
npm install react
This means:
"Download React and add it to my project."
- Node.js → lets you run JavaScript outside the browser.
- NPM → helps you install, update, and manage packages used in JavaScript/Node.js projects.
NPM comes automatically when you install Node.js.
NPM is a package manager for JavaScript and Node.js that is used to install, update, and manage packages in a project.
Parcel and Webpack are module bundlers.
In simple words, they take all the files your project needs and prepare them to run efficiently in the browser.
For example, your project may have:
App.js
Header.js
Button.js
style.css
images
React
Parcel/Webpack collect these files and their dependencies and create optimized files that the browser can load.
They help with:
- 📦 Bundling → combine project files
- ⚡ Optimization → make files smaller and faster
- 🔄 Hot Reloading → changes appear quickly while developing
- 🖼️ Asset Handling → CSS, images, fonts, etc.
- 🚀 Production Build → create optimized files for deployment
Think of Parcel/Webpack like packing your luggage 🧳.
You have clothes, shoes, books, and accessories scattered around.
Parcel/Webpack = the person who organizes and packs everything properly into luggage.
| Parcel | Webpack |
|---|---|
| Easier to set up | More configuration |
| Mostly works automatically | Highly configurable |
| Beginner-friendly | More control |
| Less configuration needed | Commonly customized in complex projects |
Parcel and Webpack are module bundlers that bundle, optimize, and manage all the files and dependencies of a web application so it can run efficiently in the browser.
.parcel-cache is a folder created by Parcel to store temporary/cache files.
Think of it as Parcel's memory 🧠.
When you run:
npm start
Parcel processes your files. Instead of doing all the work from scratch every time, it stores some processed information inside .parcel-cache.
It makes development faster ⚡.
For example:
First run:
Parcel → process everything → takes some time
Next run:
Parcel → uses cached information → faster
Suppose you have:
App.js → Parcel → processed information → .parcel-cache
Now you change App.js.
Parcel detects the change:
App.js (changed)
↓
Parcel detects the change
↓
Checks the cache
↓
Re-processes what is necessary
↓
Updates the cache
So the cache does not simply become permanently outdated.
Parcel keeps track of your files and their dependencies. When something changes, it invalidates the affected cached data and rebuilds/reprocesses what is necessary.
Imagine your project has 100 files and you change only one file.
Without caching:
Change 1 file
↓
Process all 100 files ❌
With caching:
Change 1 file
↓
Parcel reuses unchanged work from cache
↓
Processes only what is needed ✅
That's why .parcel-cache mainly exists to make subsequent builds and development faster.
Yes.
You can safely delete .parcel-cache.
Parcel will create it again when needed.
You generally don't push .parcel-cache to GitHub.
Add it to .gitignore:
.parcel-cache/
.parcel-cachestores Parcel's cached build information to speed up subsequent builds and development. It is temporary and can be deleted safely.
If .parcel-cache doesn't exist, that's usually not a problem.
It may be because:
- You haven't run Parcel yet.
- The cache was deleted.
- Parcel is using a different cache configuration.
- The folder is hidden in your file explorer.
For example:
my-project/
├── src/
├── package.json
├── node_modules/
└── .parcel-cache/ ← may appear after running Parcel
Run:
npm start
or the Parcel command defined in your package.json.
If Parcel needs the cache, it will create/manage it automatically.
You don't need to manually create .parcel-cache.
npx is a tool that lets you run a package/command without having to install it globally.
Think of it as:
npm → install/manage packages 📦
npx → run packages▶️
To create a React project:
npx create-react-app my-app
Here, npx finds and runs create-react-app for you.
You don't need to manually install create-react-app globally first.
npx parcel index.html
This tells npx:
"Find Parcel and run it."
| NPM | NPX |
|---|---|
| Mainly used to install/manage packages | Mainly used to run packages |
npm install parcel |
npx parcel index.html |
| Adds package to your project | Executes a package/command |
npm = get/manage 📦
npx = run▶️
npxis a tool that allows you to execute packages or commands without needing to install them globally.
The simple difference is:
dependencies→ needed when your application runs
devDependencies→ needed only while developing the application
Example:
{
"dependencies": {
"react": "...",
"react-dom": "..."
},
"devDependencies": {
"parcel": "..."
}
}
These are packages your actual application needs.
Examples:
reactreact-domexpress
These are tools you need to build, test, or develop your application.
Examples:
parcelwebpack- Testing tools
- Linters
Think about building a house:
- dependencies = things that remain/useful in the house 🏠
- devDependencies = tools used while building the house 🔨
Once the house is built, you don't need the hammer, but the house still needs its doors and windows.
Normal dependency:
npm install react
Development dependency:
npm install parcel --save-dev
Or:
npm i -D parcel
Dependencies are packages required for the application to run, while devDependencies are packages required only during development, testing, or building.
dist stands for distribution.
It usually contains the final, optimized version of your project that is ready to be deployed to a server.
For example:
src/
App.js
index.html
↓ Parcel/Webpack
dist/
index.html
main.js
main.css
When you build the project:
npm run build
Parcel/Webpack takes your source code and:
- 📦 Bundles files together
- ⚡ Optimizes/minifies them
- 🗜️ Makes them smaller
- 📁 Puts the final files inside
dist
Then you can deploy the dist folder.
Think of:
src → Raw materials
dist → Finished product
You work on the raw materials, but you give the finished product to the customer.
src/ → Where you write/change your code
dist/ → Final output generated by the bundler
Generally, you don't manually edit files inside dist.
The
distfolder contains the production-ready, bundled and optimized files generated by a build tool like Parcel or Webpack.
The easiest way to understand it is:
dist= final output for the browser
.parcel-cache= temporary saved work for Parcel
Your source code
↓
Parcel
↙ ↘
dist/ .parcel-cache/
Contains the final files that can be deployed.
dist/
├── index.html
├── index.js
└── index.css
- Used by the browser
- Production-ready
- Bundled and optimized
- Can be uploaded to a server
Contains Parcel's cached/processed information.
- Used by Parcel itself
- Helps make builds faster
- Not meant for the browser
- Can be deleted safely
- Parcel recreates it when needed
.parcel-cache is not simply a folder containing unbundled files.
Parcel may store already-processed pieces and metadata there.
The main difference is:
.parcel-cacheis an internal cache used by Parcel, whiledistcontains the final production output.
Imagine a factory:
src → Raw material
.parcel-cache → Factory's saved work/process information
dist → Finished product
So if you change your code:
src changes
↓
Parcel checks/reuses cache
↓
Processes necessary changes
↓
Updates dist
distcontains the final build that is served/deployed, while.parcel-cachestores Parcel's cached processing information to make future builds faster.
Browserslist tells tools which browsers your website should support. 🌐
For example:
{
"browserslist": [
"last 2 versions",
"not dead"
]
}
This basically means:
"Make my website work properly with the latest 2 versions of major browsers, and don't worry about browsers that are no longer maintained."
Different browsers support different JavaScript and CSS features.
For example:
Your code
↓
Parcel/Babel
↓
Browserslist says which browsers to support
↓
Code is transformed if necessary
↓
Browser-compatible output
If you're using a new JavaScript feature, your build tools can use Browserslist information to decide whether that code needs to be transformed for older browsers.
Usually in package.json:
{
"browserslist": [
"last 2 versions"
]
}
Imagine you're making a movie and asking:
"Who should be able to watch this movie?"
Browserslist is like telling the production team:
"Make sure this movie works for these audiences."
Similarly:
Browserslist = tells build tools which browsers your website needs to support.
Browserslist is a configuration that specifies which browsers and browser versions a web application should support, allowing tools like Parcel and Babel to generate compatible code.
| Topic | Simple Meaning |
|---|---|
| NPM | Installs and manages JavaScript packages |
| NPX | Runs packages/commands |
| Parcel/Webpack | Bundles and optimizes project files |
.parcel-cache |
Stores Parcel's cached processing information |
dist |
Contains the final production-ready build |
dependencies |
Packages needed by the application |
devDependencies |
Packages needed during development/building |
| Browserslist | Specifies which browsers your website should support |
Your Source Code
↓
┌─────────────────┐
│ Parcel/Webpack │
└─────────────────┘
↙ ↘
↓ ↓
.parcel-cache dist
(cache/work) (final output)
↓
Browser
NPM → manages packages
NPX → runs packages
Parcel/Webpack → bundles the project
.parcel-cache→ saves Parcel's previous work
dist→ final production output
Browserslist → tells tools which browsers to support