With PHP or Java, you let your business logic runs on the server, letting the client download most of the HTML already prepared. The user browser then just has to download and render that data. It also means that your server has to produce all that stuff, including pretty CPU- and memory-expensive HTML and XML.
What does that mean for the billing costs? Basically, you can save CPU usage on the host - thus having less billed, and also you can save bandwidth either with code lighter than the generated HTML, or code that makes your page application-like and not website-like. Let's picture that this way: with JS you can make your site load the code only once, and after that it will only exchange light JSON data with the server. With a Java or PHP implementation, you'll have many pages downloads. So the gain with JS is higher when you intend your user to stay longer on the site.