As per my experience, the screen rotation behaviour across different devices is not the same. The events such as resize and orientation may not fire simultaneously and occur at different timeframes.

The values such as window.orientation and screen.width may not change at the right time. Also, the screen.width does not work in the iPhone's Safari browser. So, it is recommended to not rely on the screen.width.

Listening to both window.resize and window.orientation events is the best approach. As said, android devices don't report the orientationChange when the device screen rotates. As a fail safe mechanism to listen to orientationChange events every two seconds.

Following is the code to do this and it will work for both ios and android.

var prevOrientation = window.orientation;
var orientationCheck = function(){
    if(window.orientation !== prevOrientation){
        prevOrientation = window.orientation;
        // Device orientation got changed. Write your logic here.

window.addEventListener("resize", orientationCheck, false);
window.addEventListener("orientationchange", orientationCheck, false);

// The following code is "optional" as this is paritulary for android where sometimes window.orientation fails to get updated with the right value.
setInterval(checkOrientation, 2000);