While doing research on CSS and JS codes that run before the user sees the content, something was stuck to my mind. When exactly were CSS media queries were running? Which js and jquery function run first (document.onload, document.ready etc.)? When I did research on it I found This and This questions which explain the difference between domcontentloaded, document.ready and window.onload functions. However, I could not figure out when exactly media queries in CSS run compared to these functions. So I checked it through JSFiddle in here.
In HTML part I only wrote a div with and ID;
<div id="testDiv">
Test Media Queries And JS Functions
</div>
In CSS there was only 1 media query that ran;
@media screen and (min-width:1px){
#testDiv{
color: black;
}
}
And in JS part, there was different load functions
$('document').ready(function() {
document.getElementById("testDiv").style.color = "blue";
});
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("testDiv").style.color = "red";
});
window.onload = function() {
document.getElementById("testDiv").style.color = "yellow";
};
The CSS code and its effects were visible for a brief moment. And than the div was turning to blue when I ran the code. However, I encountered a strange problem. Only in Google Chrome New Tab (Not Incognito), the code ran as yellow which means window.onload was running last and in all other browsers and tabs shows the div as blue.
Google Chrome Not Incognito Tab
Google Chrome Incognito Tab and Safari New Tab
First of all is this some kind of bug that I encountered or somehow is it intended to run like this?
Second of all, I could not find any documentation on when exactly media queries run compared to these functions.
If anyone has a link for documentation on CSS queries and their exact execution time, I would really appreciate it.