Loading ads with media-aware javascript