How can I avoid the output of my module is cached? I have a module I wrote that prints dynamic data for JavaScript variables. 

function javascript_api_page_attachments(array &amp;$page) {
$page['#attached']['html_head'][] = [
        // The data.
    [
        '#type' =&gt; 'html_tag',
        // The HTML tag to add, in this case a  tag.
        '#tag' =&gt; 'script',
        // The value of the HTML tag, here we want to end up with alert("Hello world!");.
        '#value' =&gt; javascript_api_print_parameters(),

    ],
    // A key, to make it possible to recognize this HTML  element when altering.
    'hello-world'
];}


My problem is when Drupal caches the page.Need to stop caching my pages in drupal.

How can I avoid the output of my module is cached?
As Eyal mentioned, you can pass the variables from your module to jQuery like this:

mymodule.module

function mymodule_page_attachments(array &amp;$attachments) {
    $attachments['#attached']['library'][] = 'mymodule/auto';
    $attachments['#attached']['drupalSettings']['cool'] = 'hello world';     
  }
}


mymodule.libraries.yml

auto:
  version: 1.0
  js:
    js/auto.js: {}
  dependencies:
      - core/jquery


auto.js

(function($, Drupal, drupalSettings) {

    $( document ).ready(function() {
      alert(drupalSettings.cool);
    });

})(jQuery, Drupal, drupalSettings);


This will show a js alert message saying "hello world".