dynamic external javascript generated using php

Rather than generating whole script dynamically it would make more sense (from logical and caching perspective) to use static script that will fetch data required via generic Ajax request to WP.