{"id":36,"date":"2019-02-02T13:11:08","date_gmt":"2019-02-02T13:11:08","guid":{"rendered":"https:\/\/www.onlinenote.in\/php\/?p=36"},"modified":"2019-06-06T08:36:14","modified_gmt":"2019-06-06T08:36:14","slug":"clear-the-browser-cache-of-css-or-javascript-using-php","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/","title":{"rendered":"Clear the browser cache of CSS or JavaScript Using PHP"},"content":{"rendered":"<p>Other than caching every hour, or every week, you may cache according to file data.<\/p>\n<pre class=\"lang:default decode:true \">&lt;script src=\"js\/my_script.js?v=&lt;?=md5_file('js\/my_script.js')?&gt;\"&gt;&lt;\/script&gt;<\/pre>\n<p>or use file modification time:<\/p>\n<pre class=\"lang:default decode:true \">&lt;script src=\"js\/my_script.js?v=&lt;?=filemtime('js\/my_script.js')?&gt;\"&gt;&lt;\/script&gt;<\/pre>\n<p>or use file modification every hour:<\/p>\n<pre class=\"lang:default decode:true \">&lt;script type=\"text\/javascript\" src=\"js\/myscript.js?v=&lt;?php echo date('YmdHis'); ?&gt;\"&gt;&lt;\/script&gt;<\/pre>\n<p>or Using Javascript<\/p>\n<pre class=\"lang:default decode:true \">function reloadScripts(toRefreshList\/* list of js to be refresh *\/, key \/* change this key every time you want force a refresh *\/) {\r\n    var scripts = document.getElementsByTagName('script');\r\n    for(var i = 0; i &lt; scripts.length; i++) {\r\n        var aScript = scripts[i];\r\n        for(var j = 0; j &lt; toRefreshList.length; j++) {\r\n            var toRefresh = toRefreshList[j];\r\n            if(aScript.src &amp;&amp; (aScript.src.indexOf(toRefresh) &gt; -1)) {\r\n                new_src = aScript.src.replace(toRefresh, toRefresh + '?k=' + key);\r\n                \/\/ console.log('Force refresh on cached script files. From: ' + aScript.src + ' to ' + new_src)\r\n                aScript.src = new_src;\r\n            }\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Other than caching every hour, or every week, you may cache according to file data. &lt;script src=&#8221;js\/my_script.js?v=&lt;?=md5_file(&#8216;js\/my_script.js&#8217;)?&gt;&#8221;&gt;&lt;\/script&gt; or use file modification time: &lt;script src=&#8221;js\/my_script.js?v=&lt;?=filemtime(&#8216;js\/my_script.js&#8217;)?&gt;&#8221;&gt;&lt;\/script&gt; or use file modification every hour: &lt;script type=&#8221;text\/javascript&#8221; src=&#8221;js\/myscript.js?v=&lt;?php echo date(&#8216;YmdHis&#8217;); ?&gt;&#8221;&gt;&lt;\/script&gt; or Using Javascript function reloadScripts(toRefreshList\/* list of js to be refresh *\/, key \/* change this key every time [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Clear the browser cache of CSS or JavaScript Using PHP - PHP<\/title>\n<meta name=\"description\" content=\"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Clear the browser cache of CSS or JavaScript Using PHP - PHP\" \/>\n<meta property=\"og:description\" content=\"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-02T13:11:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-06-06T08:36:14+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/\",\"url\":\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/\",\"name\":\"Clear the browser cache of CSS or JavaScript Using PHP - PHP\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/php\/#website\"},\"datePublished\":\"2019-02-02T13:11:08+00:00\",\"dateModified\":\"2019-06-06T08:36:14+00:00\",\"author\":{\"@id\":\"\"},\"description\":\"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/php\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Clear the browser cache of CSS or JavaScript Using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/php\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/php\/\",\"name\":\"PHP\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/php\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Clear the browser cache of CSS or JavaScript Using PHP - PHP","description":"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/","og_locale":"en_US","og_type":"article","og_title":"Clear the browser cache of CSS or JavaScript Using PHP - PHP","og_description":"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.","og_url":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/","og_site_name":"PHP","article_published_time":"2019-02-02T13:11:08+00:00","article_modified_time":"2019-06-06T08:36:14+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/","url":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/","name":"Clear the browser cache of CSS or JavaScript Using PHP - PHP","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/php\/#website"},"datePublished":"2019-02-02T13:11:08+00:00","dateModified":"2019-06-06T08:36:14+00:00","author":{"@id":""},"description":"Simplest method to Clear the browser cache of CSS or JavaScript Using PHP. Other than caching every hour, or every week, you may cache according to file.","breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/php\/clear-the-browser-cache-of-css-or-javascript-using-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/php\/"},{"@type":"ListItem","position":2,"name":"Clear the browser cache of CSS or JavaScript Using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/php\/#website","url":"https:\/\/www.onlinenote.in\/php\/","name":"PHP","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/php\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/posts\/36"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":1,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/posts\/36\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/php\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}