1. /**
  2. * Reloads configuration from URL parameters.
  3. * Useful for exploratory work with synchronous execution.
  4. */
  5. function reloadConfigFromURL() {
  6. // Get URL parameters.
  7. const params = new URLSearchParams(window.location.search);
  8. // Define default configuration values. Replace with your actual defaults.
  9. const defaultConfig = {
  10. apiEndpoint: 'https://default.api.com',
  11. timeout: 5000,
  12. debugMode: false,
  13. };
  14. // Merge default configuration with URL parameters.
  15. const config = { ...defaultConfig, ...new URLSearchParams(window.location.search) };
  16. // Perform any necessary actions with the updated configuration.
  17. // For example, update application state or reinitialize components.
  18. console.log("Reloaded configuration:", config);
  19. // Example: Update a global variable with the config.
  20. window.appConfig = config;
  21. }
  22. // Call the function to reload the configuration on page load.
  23. reloadConfigFromURL();
  24. // Optionally, add a button to trigger the reload manually.
  25. // Example:
  26. /*
  27. document.getElementById('reloadConfigButton').addEventListener('click', reloadConfigFromURL);
  28. */

Add your comment