
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
staticdelivr
Advanced tools
StaticDelivr simplifies image delivery by optimizing performance through CDN integration, format conversion, and dynamic resizing. Perfect for React applications.
StaticDelivr is a lightweight React library for optimizing image delivery by leveraging StaticDelivr's CDN. It simplifies image optimization with support for resizing, quality adjustments, and format conversions, ensuring your application delivers the best possible image performance.
Install the package via npm:
npm install staticdelivr
Or using yarn:
yarn add staticdelivr
import React from 'react';
import { StaticDelivrImage, StaticDelivr } from 'staticdelivr';
// Configure the base URL for relative image paths
StaticDelivr.set({ baseURL: 'https://example.com/images/' });
const App = () => (
<div>
<StaticDelivrImage
src="local/image.png"
width={800}
height={600}
quality={80}
format="webp"
alt="Optimized Image"
/>
</div>
);
export default App;
| Prop | Type | Required | Description |
|---|---|---|---|
src | string | Yes | The source URL of the image. |
width | number | No | Desired width of the image. |
height | number | No | Desired height of the image. |
quality | number (0-100) | No | Quality of the image (default is 100). |
format | 'webp', 'jpeg', 'png', 'avif' | No | Image format (e.g., webp, jpeg, png, avif). |
alt | string | No | Alternative text for the image (default is an empty string). |
className | string | No | Additional CSS classes for styling the image. |
The base URL is used for resolving relative image paths and is configured globally. This means once you set it using StaticDelivr.set(), it will apply across your entire application unless changed.
StaticDelivr.set({ baseURL: 'https://example.com/images/' });
This configuration is especially useful when working with relative URLs. If a relative path is provided in the src prop, it will be automatically resolved using the global baseURL. If you pass an absolute URL to the src prop, the base URL will not be applied.
You can configure the base URL globally in a file like _app.tsx in a Next.js application:
// pages/_app.tsx
import React from 'react';
import { StaticDelivr } from 'staticdelivr';
StaticDelivr.set({ baseURL: 'https://example.com/images/' });
const MyApp = ({ Component, pageProps }) => <Component {...pageProps} />;
export default MyApp;
<StaticDelivrImage
src="https://other-cdn.com/image.jpg"
width={400}
height={300}
quality={90}
format="jpeg"
alt="External Image"
/>
<StaticDelivrImage
src="/path/to/image.jpg"
width={500}
height={400}
quality={70}
format="png"
alt="Local Image"
/>
StaticDelivr is designed to be straightforward to integrate into your application. You can directly replace your existing <img> tags or components like the Next.js <Image> tag with StaticDelivrImage, making it a seamless transition for projects looking to optimize image delivery.
For example, in a Next.js application, if your images are stored in the public directory, they are typically accessed as:
<img src="/images/photo.jpg" alt="Example" />
By using StaticDelivrImage and configuring the baseURL to your website's domain, you can optimize these images effortlessly:
StaticDelivr.set({ baseURL: 'https://example.com' });
<StaticDelivrImage
src="/images/photo.jpg"
width={800}
height={600}
quality={85}
format="webp"
alt="Example"
/>
Here, the baseURL ensures that relative paths (e.g., /images/photo.jpg) are resolved to https://example.com/images/photo.jpg, streamlining image optimization and delivery.
To run the test suite:
npm test
Ensure code quality by running:
npm run lint
Build the library for distribution:
npm run build
Contributions are welcome! Please open an issue or submit a pull request for any enhancements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
StaticDelivr is inspired by the need for efficient and reliable image delivery solutions. Special thanks to all the contributors at StaticDelivr.
FAQs
StaticDelivr simplifies image delivery by optimizing performance through CDN integration, format conversion, and dynamic resizing. Perfect for React applications.
We found that staticdelivr demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.