How can I ignore images and other unnecessary files to lower response time in Jsoup

Hiden :

I have been fetching html documents with Jsoup like this:

Jsoup.connect(url).get();

But I have noticed that Jsoup waits for everything to load before giving me the data. I know that the data I'm looking for is in the Html document. when looking at a response (through google Chrome Network analysis tool) that the html document is sent the first ~100ms and I don't want to wait an extra ~1500ms to get access to that data.

Is there a way to make the request skip the unneeded files or stop the request after Revinge the html document?

any recommendations that could make the process of fetching the data a bit faster would be very appreciated.

Samuel Philipp :

Your assumption is actually wrong. Jsoup only fetches the one document you pass the url to. It does not fetch any resources (images, css, js files, etc.) automatically. You can take a look at the source code to prove that. Jsoup will only follow redirects, if activated.

Maybe the server delays the response, because you send a request without a User-Agent header. You can solve this using Connection.userAgent() and add e.g. the chrome user agent:

Jsoup.connect(url)
        .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36")
        .get();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=136302&siteId=1