Reputation: 12457
For those of us who run content websites and deal with Ad networks, combating malicious or malfunctioning rogue ads can be frustrating.
I own a site that embeds a lot of Youtube & Dailymotion videos. Once in awhile, a bad Ad will turn up and make the video playback stutter. I always dealt with these on a case-by-case basis. But, is there a way to detect (using javascript) whether or not the page is slow?
In my head, a very crude way is to have a setInterval running at 100ms. And if it detects a big delay in one interval, act accordingly.
Are there other more elegant approaches?
Upvotes: 9
Views: 136
Reputation: 6926
First approach, if your slowness is on load, create placeholders for the ads and load them very last after everything else.
Second approach, create a Javascript timer or include a timer library to measure the page load time. If it is greater than your acceptable threshold then kill the ad with Javascript or log the slowness to a web service.
Third approach, if the timer does not pick up the slowness because it is incremental then use a setTimeout function that records a timestamp and calls itself every 200ms and compares the new timestamp each call to the older timestamp from the previous call.
If a setTimeout call set to run at 200ms takes 500ms to finally run then you've got substantial delay and should kill the ad with Javascript or log the slowness to a web service.
Each of these methods will need to be tuned to your actual site.
Upvotes: 1