I wasn't sure if this was a PHP question, jQuery, or .htaccess...
I load a PHP script for subnavigation using jQuery's $.get, mainly because the output is pretty lengthy (about 1.2kb) and it's not critical for the rest of the page to be usable. So it's one of the things I wait to load after the rest of the page has loaded.
The $.get looks like this:
$(function() {
$.get(home + '/includes/load_subnav.php', function(data) {
var vars = data.split(';');
for (var i = 0; i < vars.length; i++) {
var b = vars[i].split(' = ');
b[0] = b[0].trim();
subnavArr[decodeURIComponent(b[0])] = decodeURIComponent(b[1] || '');
}
});
});
And in the .htaccess I have:
<FilesMatch "load_subnav\.php|\.(ico|css|js|jpg|jpeg|png|gif)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
But when I use Google Dev Tools > Network, it doesn't show that it's loading from cache. Why not? Is the
function(data) messing it up? Or do I need to include a relative/absolute path in the .htaccess?
The load time is only about 370ms so it's not huge, but if I could get it to load from cache then it should drop down to around 50ms... and every little chip away helps! :-)