don't do server pushes for unneccesary resources on ajax topics

save bytes in init.js
This commit is contained in:
Azareal 2020-03-13 19:02:28 +10:00
parent bfea6b740f
commit 4d8858b846
2 changed files with 11 additions and 24 deletions

View File

@ -8,7 +8,7 @@ var ranInitHooks={}
function runHook(name,...args) { function runHook(name,...args) {
if(!(name in hooks)) { if(!(name in hooks)) {
console.log("Couldn't find hook '" + name + "'"); console.log("Couldn't find hook '"+name+"'");
return; return;
} }
console.log("Running hook '"+name+"'"); console.log("Running hook '"+name+"'");
@ -37,9 +37,7 @@ function addInitHook(name,h) {
} }
// Temporary hack for templates // Temporary hack for templates
function len(it) { function len(it) {return it.length;}
return it.length;
}
function asyncGetScript(src) { function asyncGetScript(src) {
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
@ -105,12 +103,11 @@ function notifyOnScript(src) {
function notifyOnScriptW(name,complete,success) { function notifyOnScriptW(name,complete,success) {
notifyOnScript(name) notifyOnScript(name)
.then(() => { .then(() => {
console.log("Loaded " +name+".js"); console.log("Loaded "+name+".js");
complete(); complete();
if(success!==undefined) success(); if(success!==undefined) success();
}).catch(e => { }).catch(e => {
console.log("Unable to get script name '"+name+"'"); console.log("Unable to get script name '"+name+"'",e);
console.log("e",e);
console.trace(); console.trace();
complete(e); complete(e);
}); });
@ -119,9 +116,9 @@ function notifyOnScriptW(name,complete,success) {
// TODO: Send data at load time so we don't have to rely on a fallback template here // TODO: Send data at load time so we don't have to rely on a fallback template here
function loadScript(name,callback,fail) { function loadScript(name,callback,fail) {
let fname = name; let fname = name;
let value = "; " + document.cookie; let value = "; "+document.cookie;
let parts = value.split("; current_theme="); let parts = value.split("; current_theme=");
if (parts.length == 2) fname += "_"+ parts.pop().split(";").shift(); if(parts.length==2) fname += "_"+parts.pop().split(";").shift();
let url = "/s/"+fname+".js" let url = "/s/"+fname+".js"
let iurl = "/s/"+name+".js" let iurl = "/s/"+name+".js"
@ -133,8 +130,7 @@ function loadScript(name,callback,fail) {
asyncGetScript(iurl) asyncGetScript(iurl)
.then(callback) .then(callback)
.catch(e => { .catch(e => {
console.log("Unable to get script '"+iurl+"'"); console.log("Unable to get script '"+iurl+"'",e);
console.log("e",e);
console.trace(); console.trace();
}); });
} }
@ -144,17 +140,7 @@ function loadScript(name,callback,fail) {
}); });
} }
/*function loadTmpl(name,callback) { function RelativeTime(date) {return date;}
let url = "/s/"+name
let worker = new Worker(url);
}*/
function DoNothingButPassBack(it) {
return it;
}
function RelativeTime(date) {
return date;
}
function initPhrases(loggedIn, panel=false) { function initPhrases(loggedIn, panel=false) {
console.log("in initPhrases") console.log("in initPhrases")
@ -173,7 +159,7 @@ function fetchPhrases(plist) {
console.log("loaded phrase endpoint data"); console.log("loaded phrase endpoint data");
console.log("data",data); console.log("data",data);
Object.keys(tmplInits).forEach(key => { Object.keys(tmplInits).forEach(key => {
let phrases = []; let phrases=[];
let tmplInit = tmplInits[key]; let tmplInit = tmplInits[key];
for(let phraseName of tmplInit) phrases.push(data[phraseName]); for(let phraseName of tmplInit) phrases.push(data[phraseName]);
console.log("Adding phrases"); console.log("Adding phrases");

View File

@ -128,6 +128,7 @@ func renderTemplate3(tmplName, hookName string, w http.ResponseWriter, r *http.R
if h.CurrentUser.Loggedin { if h.CurrentUser.Loggedin {
h.AddScriptAsync("member.js") h.AddScriptAsync("member.js")
} }
h.CurrentUser.LastAgent = 0
} }
if h.CurrentUser.Loggedin { if h.CurrentUser.Loggedin {