What can I do to further improve image load speeds?
Am I using the current tools correctly?
I'm learning Next.js and for loading images, my current project uses Next/Image and has sharp.js installed. My load times within reason.
Here is how I'm using the Image tag, feedback of any kind is appreciated.
// items is an array of image urls
{items.map((src, index) => {
return (
<Image
src={src}
alt=""
layout="fill"
objectFit="cover"
priority={index === 0}
></Image>
);
})}
Related
I have a problem with serving a static image from my public/images folder.
It correctly displays in the files I've been working on so far EXCEPT the dynamic file [itemId].js (shown in the picture below)
The most interesting clue I have is this error in the console.
http://localhost:3000/items/_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=1920 404 (Not Found)
It tries to serve from /items, which is not what I want at all...
Does anyone know what's the trick behind this? If you need more informations, let me know.
// in components/Header.js (which is wrapping all of my pages)
import bannerBig from "../public/images/banner-big.png";
// then i use it this way with the Image component from next/image
<Image src={bannerBig} alt="midnight city" width={1920} height={800}/>
The img generated by the <Image /> component looks like this and is the same accross all of my pages:
<img alt="midnight city" src="_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=3840" decoding="async" style="position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%" srcset="_next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=1920 1x, _next/static/image/public/images/banner-big.f496e182c5dd297c1d1c030d9b7436d8.png?auto=format&fit=max&w=3840 2x">
so I finally fixed the problem by adding a '/' before my static image path so it's always being served from the root
<Image
src={"/" + bannerBig.src}
alt="midnight city"
width={bannerBig.width}
height={bannerBig.height}
/>
I am working on a product page which has an Image gallery on the left and color selections on the right.
See the below image.
Now every time a color is selected a set of image has to be shown on the left. The way it is implemented right now is that every time the color selection is updated the store value for SelectedImages changes with the array of that particular color.
Now it makes sense that, whenever I switch to a new color the image is loaded. Which is happening.
But the issue I am facing is that whenever the color is changed, and the SelectedImages array is updated the images are loaded, no matter that they were loaded earlier. I don't want it to load again (send http) when it has already called the image once.
Also, I don't want to load all the images (4 color x 4 images = 16 Images) at once which would again be not performant.
I have created this UI using vue. It's not a vue single app, but it has vue component at some places where needed.
Code that renders Image.
<div class="desktop-gallery"
:class = "{ 'is_loading': isLoading }"
v-bind:style="parentStyle"
v-show="!onlyMobile">
<div class="gallery-item"
v-for="(image, index) in images" :key="index"
ref="variableGallery"
#click="handleGalleryZoom(index)"
>
<img :src="image"/>
</div>
</div>
im trying to display an image in vue component
<img :src="profile.photoes[0].picture"/>
(like this), but i m not getting it.
However, if i do
<img :src="'../../'+profile.photoes[0].picture"/> ( I m able to get the image.
why there are two behaviour of the same line of code. Does the folders in Laravel view, makes any difference ??
I've a ploblem with image Source and Obj's parameter.
Inside the local object I have IMG_NAME: 'A.png' like so:
I would like concatenate this value with source like
but I know require doesn't support concatenate so I decided ask you this question about the best way to solve this problem.
How can I try to solve this problem (my solve screenshot), and error image (Error reponse)
If you can modify the local object change to this
{
"id_letter": "1",
"name_letter": "A",
"image" require("./app/assets/images/A.png")
}
and then Component change to
<Image style={styles.letter_image} source={data.image} />
Edit Another Method use switch case statement
require not support dynamic path. Use switch case statement to solve this
function getImage(img_name) {
switch(img_name) {
case "A.png": return require("./app/assets/images/A.png");
case "B.png": return require("./app/assets/images/B.png");
}
}
<Image style={styles.letter_image} source={getImage(data.img_name)} />
I think there are 4 simple way to use a dynamic source in the Image Component:
1) You can use images that are already bundled into the app:
Images From Hybrid App's Resources If you are building a hybrid
app (some UIs in React Native, some UIs in platform code) you can
still use images that are already bundled into the app.
For images included via Xcode asset catalogs or in the Android
drawable folder, use the image name without the extension:
< Image source={{uri: 'app_icon'}} style={{width: 40, height: 40}} />
For images in the Android assets folder, use the asset:/ scheme:
< Image source={{uri: 'asset:/app_icon.png'}} style={{width: 40,
height: 40}} />
These approaches provide no safety checks. It's up to you to guarantee
that those images are available in the application. Also you have to
specify image dimensions manually.
https ://facebook.github.io/react-native/docs/images.html#images-from-hybrid-app-s-resources
2) You can use require('imagePath') into the object.
{
"id_letter": "1",
"name_letter":"A",
"img_name":require('./app/assets/images/imgname.jpg');
}
3) You can storage the images in the web and you can use:
<Image source={{uri: 'http: //site.com/app/assets/images/'+data.img_name}}/>
4) You can storage the images using the library https://github.com/wkh237/react-native-fetch-blob.
I'm trying to load and resize and transform the image in the background while the application main data is loading. I need to do this because some of images are too big and I have a lot of them, so, I thing it's better to prepare all images before showing.
I execute this code in the background:
Load the image from Uri:
ImageService.Instance.LoadUrl(uri, TimeSpan.FromDays(60))
.DownSample(100, 100, false).Preload();
Load the same image and apply additional transformation to it:
ImageService.Instance.LoadUrl(uri, TimeSpan.FromDays(60))
.DownSample(100, 100, false).Transform(BlurredTransformHere).Preload();
How I could reuse later the result from these cache queries in the CachedImage?
<forms:CachedImage
x:Name="Blured"
Aspect="Fill"
CacheType="All"
HorizontalOptions="Fill"
Opacity="0.3"
VerticalOptions="Fill"/>
<forms:CachedImage
x:Name="Normal"
CacheType="All"
Aspect="AspectFit"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
Should I add the same config parameters as in the query for each CachedImage? e.g. add DownsampleHeight&W and BlurredTransformation with the same parameters value?
The Transformations do not affect the cached version of your Image, they just change the way the imageSource is rendered.
In your case for the Image preloading you could apply the DownSample and later use the transformation in your CachedImage control.
<forms:CachedImage
x:Name="Blured"
Aspect="Fill"
CacheType="All"
HorizontalOptions="Fill"
Opacity="0.3"
Source="YOUR_SOURCE_URI"
VerticalOptions="Fill">
<forms:CachedImage.Transformations>
<fftransformations:BlurredTransformation Radius="30"/>
</forms:CachedImage.Transformations>
</forms:CachedImage>