How do HTML, CSS, and JavaScript interact to render a dynamic webpage, and how would you optimize frontend performance?