0

I have ajax-call which request html from local proxy php file. This proxy downloads html from external server and returns, where html is parsing via jQuery.

$.ajax({
    type: 'POST',
    url: 'proxy.php',
    data: {
        goal: 'get',
        url: url
    },
    success: function(page) {

        let p = $(page),
            h1 = p.find('h1');

        //some code

        //<-- problem begins

    },
    error: function(response) {
        console.error(response);
    }
});

After doing some code it throws in browser console a lot of 404-errors, while trying download some external images, what leads to high processor load. Actually i don't need those images at all, i just need plain html.

I've tried these methods to free some memory but it was useless:

p.remove();
p = undefined;

How to prevent loading images or maybe remove variable after using it?

  • 1
    Please post what you are getting in page variable and what you want to do with it – Just code May 20 '19 at 04:33
  • @Justcode, i'm getting simple html page what contains images with src-attributes links to another-one server. I need to get text data via jQuery selectors. While i'm getting text (in "some code" comment) everything works fine, but then it throws errors. –  May 20 '19 at 04:41
  • so, where is the problem? please specify a problem you are actually facing – Just code May 20 '19 at 04:43
  • @Justcode, i guess after declaring "p" variable browser starts loading images and can't find them because all of them are on external server. I need to prevent images loading but save opportuniti to use jQuery selectors on that html. –  May 20 '19 at 04:56

1 Answers1

0

After a couple of minutes research i've found this solution and wrote simple function for cleaning and storing src-attribute:

cleanAndStoreSrc: function(html) {

    let h = $(html);

    h.find('img').each(function (ind, el) {
        let t = $(this),
            src = t.attr('src');
        t
        .attr('src-reserved', src)
        .removeAttr('src');
    });

    return h;

}

If any more effective or elegant solution will be posted i will accept it as answer.