Encountering issues with template caching in my MEAN app. The navigation bar uses conditional logic to show/hide buttons based on user status. Upon page load, values are null or false until login (views, isLoggedIn).
The problem arises post-login - despite successful authentication and redirection using
$location.path("/pathAfterLogin");
, hidden buttons persist. Only hard refresh (Ctrl-F5) reflects correct button display based on app.js values.
Tech stack: Angular 1.5, UI-Router, Express 4, Swig templates, consolidate. NODE.ENV is set to development.
Multiple attempts made at disabling cache across the application without success.
Snippet from app.js:
'use strict';
var express = require('express'),
path = require('path'),
cons = require('consolidate'),
swig = require('swig');
module.exports = function() {
var app = express(); //start an express app app.disable('view cache');
app.engine('html', cons.swig);
app.set('view engine', 'html');
app.set('views',path.join(__dirname,'../app/views'));
app.set('view cache', false ); //set cache
swig.setDefaults({ cache: false });
app.get('*', stuff.test, function(req, res, next) {
res.setHeader('Cache-Control', 'no-cache');
res.render('index', {
cache: false,
views: req.views,
isLoggedIn: req.isLoggedIn
});
});
return app;
};
HTML file serves as main layout/view for this single-page application. Index.html includes a navigation file.
Included navigation file:<div id="subtitle">
<ul class="nav nav-pills pull-right">
{% if !isLoggedIn %}<li ui-sref-active="active"><a ui-sref="login">Login</a></li>{% endif %}
{% if isLoggedIn %}<li ui-sref-active="active"><a ui-sref="logout">Logout</a></li>{% endif %}
{% for item in views %}
{% if item == "linkA" %}<li ui-sref-active="active"><a ui-sref="linkA">LinkA</a></li>{% endif %}
{% if item == "LinkB" %}<li ui-sref-active="active"><a ui-sref="linkB">LinkB</a></li> {% endif %}
{% endfor %}
{% if !isLoggedIn %}<li ui-sref-active="active"><a ui-sref="info">Info </a></li>{% endif %}
<li class="dropdown"ui-sref-active="active">
{% for item in views %}
{% if resource == "mainDD" %} <a class="dropdown-toggle" data-toggle="dropdown" href="#"> Drop Downs <span class="caret"></span></a>
<ul class="dropdown-menu">
{% for item in permissions %}
{% if item == "link1" %}<li><a ui-sref="link1">Link 1</a></li>{% endif %}
{% if item == "link2" %}<li><a ui-sref="link2">Link 2</a></li>{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</li>
</
Inquiry:
- Is caching correctly disabled? If not, pinpoint issue.
- Is observed behavior typical for cache disablement?