K
K
Kak_B_CTapou_Cka3ke2020-04-21 17:34:38
JavaScript
Kak_B_CTapou_Cka3ke, 2020-04-21 17:34:38

How to bulk replace links to images?

Hey!
I would be grateful if you could help me with a solution. The site has pictures with links like site.ru/_pu/15/18034358.jpg to reduce the load on the site, I uploaded all the pictures to the repository. Now I need to send pictures to users at the new address. How to replace all links to images starting with site.ru/_pu/ with site2.ru/_pu/ using js/jquery, and will this reduce the load? There is no access to php, images have no classes and id either.
Thanks for answers!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-21
@Kak_B_CTapou_Cka3ke

for (const img of document.querySelectorAll('img')) { 
  img.src = img.src.replace('site.ru', 'site2.ru')
}

^ put this in window.onload or a suitable jquery event
and will it reduce the load

yes, because first the browser will ask from site.ru and get 404

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question