Skip to content

Commit

Permalink
feat: lazy loading the home page invisible images
Browse files Browse the repository at this point in the history
  • Loading branch information
Moamal-2000 committed Oct 7, 2024
1 parent 9ef088f commit 34004a5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import useStoreWebsiteDataToLocalStorage from "./Hooks/App/useStoreWebsiteDataToLocalStorage";
import useChangeLangDirOnKeys from "./Hooks/Helper/useChangeLangDirOnKeys";
import AppRoutes from "./Routes/AppRoutes";

function App() {
useStoreWebsiteDataToLocalStorage();
useChangeLangDirOnKeys();

return <AppRoutes />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FeaturedSectionFeatures = () => {
title={t(`${featuresTransData}.title`)}
description={t(`${featuresTransData}.description`)}
key={id}
loading="lazy"
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const OurProductsSection = () => {
<ExploreProducts
numOfProducts={7}
customization={productCardCustomizations.ourProducts}
loading="lazy"
/>

<Link to="/products" className={s.viewProductsBtn}>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Home/ThisMonthSection/ThisMonthSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const ThisMonthSection = () => {
</Link>
</div>

<ProductsSlider filterFun={filterThisMonthProducts} />
<ProductsSlider filterFun={filterThisMonthProducts} loading="lazy" />
</section>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Home/TodaySection/TodaySection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TodaySection = () => {
<EventCounter eventName="flash-sales" timeEvent="3 23 19 56" />
</div>

<ProductsSlider filterFun={filterFlashSalesProducts} />
<ProductsSlider filterFun={filterFlashSalesProducts} loading="lazy" />

<Link to="/products" className={s.viewProductsBtn}>
{t("buttons.viewAllProducts")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import ProductCard from "../../ProductsCards/ProductCard/ProductCard";
import s from "./ProductsSlider.module.scss";
import SliderButtons from "./SliderButtons/SliderButtons";

const ProductsSlider = ({ filterFun = () => productsData, customization }) => {
const ProductsSlider = ({
filterFun = () => productsData,
customization,
loading,
}) => {
const filteredProducts = filterFun();
const sliderRef = useRef();
const { handleNextBtn, handlePrevBtn } = useSlider(sliderRef);
Expand All @@ -23,6 +27,7 @@ const ProductsSlider = ({ filterFun = () => productsData, customization }) => {
product={product}
key={product.id}
customization={customization}
loading={loading}
/>
))}
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/Components/Shared/MiniComponents/Feature/Feature.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import s from "./Feature.module.scss";

const Feature = ({ iconImg, iconAlt, title, description }) => {
const Feature = ({
iconImg,
iconAlt,
title,
description,
loading = "eager",
}) => {
return (
<div className={s.feature}>
<div className={s.iconHolder}>
<img src={iconImg} alt={iconAlt} />
<img src={iconImg} alt={iconAlt} loading={loading} />
</div>

<b tabIndex="0">{title}</b>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Shared/Posters/SmallPoster.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const SmallPoster = ({ title, description, posterUrl }) => {

return (
<div className={s.smallPoster} dir="ltr">
<img src={posterUrl} alt="product's poster" />
<img src={posterUrl} alt="product's poster" loading="lazy" />
<div className={s.content}>
<b>{title}</b>
<p>{description}</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const ProductCard = ({
showColors: false,
},
removeFrom,
loading = "eager",
}) => {
const { name, discount, img, id, addedDate } = product;
const {
Expand Down Expand Up @@ -62,6 +63,7 @@ const ProductCard = ({
src={img}
alt={name}
aria-label={name}
loading={loading}
onClick={navigateToProductDetails}
/>
</div>
Expand Down

0 comments on commit 34004a5

Please sign in to comment.