Whenever you try to precompile or even just cache an HTML file that relies on run time data, you are going to have to build your application in a way that is sympathetic to that. In most cases, you're going to have to figure out how to fetch the missing data on the client side and populate it into the template/runtime context.
This is an issue in Ruby, PHP, Javascript, React, Angular, Python... every single application with caching or compilation.