{"id":544,"date":"2014-06-11T21:13:45","date_gmt":"2014-06-11T21:13:45","guid":{"rendered":"http:\/\/localhost\/__sites\/3d_blog\/?p=544"},"modified":"2014-06-12T08:50:51","modified_gmt":"2014-06-12T08:50:51","slug":"no-more-cache-force-the-reload","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=544","title":{"rendered":"no more cache &#8211; force the reload"},"content":{"rendered":"<blockquote><p>Goal: to avoid the cache provided old file versions<\/p><\/blockquote>\n<p>If I load an external javascript or css file from js code like this:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n  \/\/ load a css file\r\n  var s = document.createElement('link');\r\n  s.setAttribute('rel', 'stylesheet');  \r\n  s.setAttribute('type', 'text\/css');\r\n  s.setAttribute('href', 'main.css');\r\n  document.getElementsByTagName('head')[0].appendChild(s);\r\n\r\n  \/\/ load a js file\r\n  var s = document.createElement('script');\r\n  s.type = 'text\/javascript';\r\n  s.src = 'main.js';\r\n  document.getElementsByTagName('head')[0].appendChild(s);\r\n<\/pre>\n<p>First time is ok, but second time may be I will receive the file from the cache.<br \/>\nTo avoid the cache just put some fake parameter to the end of the file request.<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\n  ...\r\n  s.setAttribute('href', 'main.css?_' + new Date().getTime());\r\n  ...\r\n\r\n  ...\r\n  script.src = 'main.js?_' + new Date().getTime();\r\n  ...\r\n<\/pre>\n<p>In this case the client will ask the server every time and never the cache.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Goal: to avoid the cache provided old file versions If I load an external javascript or css file from js code like this: First time is ok, but second time may be I will receive the file from the cache. To avoid the cache just put some fake parameter to the end of the file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-544","post","type-post","status-publish","format-standard","hentry","category-javascript","category-web-trick"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=544"}],"version-history":[{"count":6,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/544\/revisions"}],"predecessor-version":[{"id":550,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/544\/revisions\/550"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}