I've been making a few DOM modifications to the SuiteBar in 2016 using javascript/jquery and I've noticed that sometimes on first load the changes don't take at all or only some do. To fix it, reloading the page solves the problem.
I think our main issue is that we aren't using master pages but Control delegates instead and for some reason I haven't be able to force this script to load at the end of the page instead so I'm facing a timing issue on first load, likely cause the file isn't in the cache by then.
I'm trying to find a more consistent approach. This is what I'm doing:
$(function () {
// Wait for resources, then do stuff
SP.SOD.loadMultiple(['init.js', 'sp.core.js', 'sp.runtime.js', 'sp.js'], function () {
// Prepare page
var siteTitle = $('a.o365cs-nav-appTitle > span.o365cs-nav-brandingText');
siteTitle
.empty()
.text(title)
.closest('a').attr({
'href': myobject.currentPath(),
'title': myobject.returnHomeTitle
});
// Replace site logo and set link to home
$("img.ms-siteicon-img")
.attr({
"src": myobject.siteLogo,
})
.closest('a')
.attr('href', myobject.currentPath());
});
})