Answers for "refresh javascript using require"

0

refresh javascript using require

<body>
  <p id="contents">Nothing loaded.</p>
  <button id="reload">Reload</button>
  <script>
    require.config({	// require's configuration
        baseUrl: "./js",
        paths: {
            jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min', // file path
        }
    });
    require(["jquery"], function ($) {
        var $contents = $("#contents");
        function reload() {
            require.undef("text!../file.html");				 // "clear" the required code
            require(["text!../file.html"], function (file) { // re-require the code
                $contents.empty();		// your optional code (can be omitted) by just using:
                $contents.append(file); // require(["text!../file.html"]);
            });
        }
        $("#reload").click(reload);  // call the refresh function in a button or another function
    });
  </script>
</body>
Posted by: Guest on July-28-2020

Code answers related to "refresh javascript using require"

Code answers related to "Javascript"

Browse Popular Code Answers by Language