How does a plugin output JS that can be used within a cache tag?
That’s a tricky one, because right now the {% cache %} tag is only focussed on the actual HTML that gets output between its tags, but when you include Javascript using TemplatesService::includeJs, etc., that’s actually queuing up the Javascript to be output later on.

So, the trick here will be to make sure any JS that is included within the {% cache %} tag is also output within the {% cache %} tag:

{% cache %}
    {% for entry in craft.entries.section('news') %}

        {{ craft.googleMaps.data('map', entry.map) }}

        {# Output any queued-up JS #}
        {{ getFootHtml() }}

    {% endfor %}
{% endcache %}


This isn’t a perfect solution because that tag will also output any Javascript that was already queued up before the {% cache %} tag. If there is any, then it will end up getting output twice on requests where the {% cache %} tag already has cached HTML to return. Might be something we can address in a future update though.