Yeah, I've run into this as well. I would say avoid doing this if you can and use an AJAX call from inside the javascript to pull the data in that you need. Sometimes this isn't feasible/ideal though (especially if the data is slow to get/calculate and is already used on the html page...). If you can cache the results of the calculation on the server-side, that would mitigate the performance implications a bit and then you just have the overhead of the request itself.