HTML Introduction to HTML and CSS HTML: The Structural Foundation of Web Pages and Applications Image Tags

Zane Wilson
Zane Wilson
Front End Web Development Techdegree Student 2,973 Points

Placeimg random image

In the training video, when Treasure refreshes the page - it loads a new image every time. However, when I refresh the page, the image stays consistent and their is no randomization.

Is this because of the browser I'm using or is this something that I'm doing wrong when I'm inserting the code?

Code for the header is below -

<header> <img src="https://placeimg.com/400/400/people" alt="Drawing of Jane Smith" class="profile-image"> <h1 class="tag name">Hello, I’m Zane.</h1> <p class="tag location">My home is New York, New York.</p> </header>

Thanks in advance!

Regan Layman
Regan Layman
11,643 Points

copied from Steven Parker 2/4/20 comment

Most likely, your browser is trying to be efficient by caching the image. Try doing a no-cache reload if your browser has that function (most do).

You can also use a bit of JavaScript to change the URL each time to prevent the cached copy from being used:

document.querySelector("img").src += "?nocache=" + Math.random();

Note that this particular script only targets the first image on the page.

1 Answer

Steven Parker
Steven Parker
195,561 Points

Here's the answer I've given previously (as Regan observed), complete with syntax coloring:

Most likely, your browser is trying to be efficient by caching the image. Try doing a no-cache reload if your browser has that function (most do).

You can also use a bit of JavaScript to change the URL each time to prevent the cached copy from being used:

document.querySelector("img").src += "?nocache=" + Math.random();

Note that this particular script only targets the first image on the page.