what are the rules with google (or any other search engine) in regards to cloaking (e.g. showing different content for bots vs real users)
The question is what if we want to load certain content only when the user scrolls/interacts but still have google/bots (which doesn’t scroll) crawl that content.. Would it be OK to have a condition in JS that checks if this is a BOT (via userAgent) and loads that content.. but for regular user (non bots) this will only happen when they first interact with the page (e.g. mousemove keypress scroll).
It is not really cloaking as by the end of the day the content will be the same for both (as soon as the user interacts with the page)
In this particular example this is about navigation mega Menu that fetches data and loads only upon user's first interaction. This increases the page performance by not fetching unnecessary calls and heavy DOM before it is ever needed.
Sample code:
if(/bot|spider|crawler|slurp/.test(navigator.userAgent)){
// load and render content
} else {
onFirstInteraction.then(event => {
// load and render content
});
}