Avoiding unnecessary queries in javascript/erb views


I have a js view, say, things/index.js.erb that looks like this:

  $('my-stuff').update("<%= escape_javascript(render :partial =>
'shared/thing', :collection => @things) %>");
  Effect.toggle('my-stuff', 'slide');

The idea is that the div with id 'my-stuff' will slide down and show
the collection when a certain link is clicked, and it'll slide up if
clicked again. The problem is that on the second click, the file is
parsed again by erb, which results in a query being made to the
database to fetch the @things collection. This is unnecessry because
the content is already displayed and is now being hidden from the

Is there any way to detect that situation and avoid that extra query?