The most effective way to check a webpage?

As the questions say, what is the most effective way to check if a link to a website is valid?

I am currently executing the following code, but when applied to a list of 20 URLs, it takes a very long time to complete.

if let data = NSData(contentsOfURL: NSURL(string: thisURL)!) { println(thisURL) } else { println("doesn't exist") break } 
+5
source share
1 answer

The solution above only says if you have a valid Internet connection - it is assumed that Google.com is available. if you want to check the availability of a group of websites, you will need to check each of them separately - and then you are stuck with timeout restrictions.

One solution is to run 20 background tasks for simultaneous access to each website and create a common response as the results arrive.

Depending on your application, it may be fair to do the entire block of 20 in one background task - if you can start it early enough in your process, maybe it doesn’t matter that it takes a lot of time - only this does not delay the user.

0
source

Source: https://habr.com/ru/post/1239181/


All Articles