Disclaimer I am working on an edge case here. The Javascript file is dynamically created server-side, and the JSLinks all point to the same absolute URL (receiving different content). JSLink Absolute URLs are only possible on Office365/SharePoint Online
I have a View with CSR file
window.a='a';
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
var b='b';
function init() {
var c='c';
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
try{
console.log('OnPostRender',window.a,b,c);
console.log(_spPageContextInfo.serverRequestPath);
}catch(e){
console.error(e);
}
},
ListTemplateType: 101
});
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/Style Library/csr.js"), init);
init();
});
- When I open this page all is fine
- When I browse to another page (remember MDS is enabled)
- And then return to the View
- ... my globals are gone ... (a is undefined in the second OnPostRender)

everything I defined as global is gone.
If I define b as window.b its destroyed as well.
Now this is a pain because I used JSLink to load a suporting library.. in the global scope.
Note #1
Global functions are not destroyed (all the CSR examples out there are based on functions)
Note #2
Yes, there is
- https://msdn.microsoft.com/en-us/library/bb397723.aspx
- Javacript only executed on first page load
- Issues with Minimal Download Strategy and _spBodyOnLoadFunctionNames.push
- http://www.vizit.com/effect-sharepoints-minimal-download-strategy-mds/
- https://www.spcaf.com/blog/sharepoint-javascript-context-development-part-4-the-way-of-the-async-delta-manager/
- http://mariagraziamerlo.com/tag/mds/
- and more
Problem I have: My JS file is dynamically created by a PHP script (and also used by non-SharePoint sites), so it has the same filename but different content
But, after a sleepless night, I am getting there...



var jslinkOverride = window.jslinkOverride || {};in PnP: https://github.com/OfficeDev/PnP/search?utf8=%E2%9C%93&q=registerNamespace and many blogs are doing nothing – Danny '365CSI' Engelman Mar 20 '16 at 09:02