Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change out an image src="" before the original image loads

Tags:

People also ask

Can you change img src?

The required src attribute specifies the URL of an image. Note: The src property can be changed at any time. However, the new image inherits the height and width attributes of the original image, if not new height and width properties are specified.

How can I change src image in HTML?

To change the source or src of an image, you need to add an id or class to the image tag. You can get the image element using the name of the id or class , and you can change the source or src of the image using the src property.

How do I change the fallback image in HTML?

We can use the onerror attribute on the image to set a fallback. We use the onerror to set the error to null and set the src of the image to a fallback.

How do I remove the src from a photo?

To clear an image src attribute: Use the setAttribute() method to set the image's src attribute to an empty string. Alternatively, hide the image element.


I've been looking at Javascript that can change the src of an image. I'm simply wondering if this can be done before the browser attempts to fetch the original image.

Example.

Src="Large-Image"

Can I (with javascript, I would imagine.. node.JS maybe?) serve the user src="smaller-image"?

Obviously, there would be no performance gain if the browser loads the large image first.