顯示具有 cache 標籤的文章。 顯示所有文章
顯示具有 cache 標籤的文章。 顯示所有文章

2020年2月13日 星期四

[JS] RequireJS - Prevent JS File Caching

Problems
Very often when we updated the JS files, directly refreshing is not reflecting the changes, instead we need to manually clear cache, which makes end users using the web application quite annoying.


Solutions
RequireJS provides "cache busting" which can force browser to download the latest version of JS files every time new pages loaded

Basically, we write a general function accepting target path not to cache, the "require.config" will then execute the function, the bust function actually use current time and attach as the parameter of the JS URL, since time is always changing, it can force the browser to retrieve the JS files for every load


function bust(path) {
    return path + '?bust=' + (new Date()).getTime();
}

require.config({
    baseUrl: '/base/path',
    paths: {
        'fileAlias': bust('fileLikelyToChange'),
        'anotherFileAlias': bust('anotherFileLikelyToChange'),
        'jQuery': 'jQuery'
    },
});



References
- https://stackoverflow.com/questions/16523755/cache-busting-specific-modules-with-requirejs

2015年1月12日 星期一

[jQuery] Datatable: Some Hints

Be careful when using datatables, the following should take into account

  1. If you try to do some column visible/invisible work, you need to clear cookies to take effect or you may not see any differences
     
    $('#example').dataTable( {
      "columnDefs": [
        { "visible": false, "targets": 0 }
      ]
    } );

    For the above, we specify the column 0 to be invisible, but when I refresh my page, I cannot see anything, we need to clear the cookies to achieve the changes, the only reason for this I guess would be the bState parameter which use the cookie to save the sorting history and other datatable profiles.

    ***And usually you may need to restart the chrome browser with the private mode to reflect the changes***

I will update this doc if any new hints of datatables found.