fix logic for append_javascript

PR #2911 results in appending javascript even if dynamic is false,
so in current master all javascript outputs are actually run at load.
Merge pull request #2954 from minrk/fixdynamic

fix logic for append_javascript