CORE CONCEPTS
Optimizing Images
Images are the most important part of a website. They are the first thing that a user sees when they visit a website. So, it is important to optimize images to make the website load faster.
Rasengan.js provides an external package called @rasenganjs/image to display images on the website with a lazy loading feature.
The package doesn't compress images but it loads them only when they are in the viewport.
By default, when using the Rasengan CLI to create a new project, the @rasenganjs/image package is already installed.
If not, you can install it by running the following command:
bashnpm install @rasenganjs/image
First of all, you have to import the css file in your project. You can do this by adding the following line in your main.js file:
jsimport "@rasenganjs/image/css";
Then, you can use the Image component to display images on your website.
This package supports local images. You can import the image and pass it as a src prop to the Image component.
file extensions like .jpg, .jpeg, .png, .gif, .webp, .svg are supported.
jsximport React from "react"; import Image from "@rasenganjs/image"; import avatar from "@assets/images/avatar.jpg"; export default function Avatar() { return <Image src={avatar} alt="Avatar" width={200} height={200} />; }
You can also use external images by passing an object with an uri property as a src prop to the Image component.
jsximport React from "react"; import Image from "@rasenganjs/image"; export default function Avatar() { return ( <Image src={{ uri: "https://example.com/avatar.jpg" }} alt="Avatar" width={200} height={200} /> ); }