Skip to content

Instantly share code, notes, and snippets.

@taoka-toshiaki
Last active May 18, 2023 07:19
Show Gist options
  • Save taoka-toshiaki/a4b8312d69631a7d00e86d3b33839019 to your computer and use it in GitHub Desktop.
Save taoka-toshiaki/a4b8312d69631a7d00e86d3b33839019 to your computer and use it in GitHub Desktop.
jsとcssファイルを再読み込みするだけのコード。(パラメータを含むものには非対応)
"use strict";
document.querySelector("button").addEventListener("click",jsandcssreload);
function jsandcssreload(){
let d = (new Date()).getTime();
[...document.querySelectorAll("link")].forEach((elm)=>{
elm.href = elm.href.replace(/(\.css)\??[0-9]{0,}$/,".css?" + d);
});
[...document.querySelectorAll("script")].forEach((elm)=>{
elm.src = elm.src.replace(/(\.js)\??[0-9]{0,}$/,".js?" + d);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment