How do you optimize a slow-loading web page that relies heavily on database queries and external APIs?