I went to websites like Amazon, Zomato, and Swiggy when I opened the developer tool I realized they are not using <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
.
If I load their website in desktop mode and then I decrease the screen width using the dev tool, the layout does not change (as the viewport tag is not added). I found that their layout type is based on the initial loading width of the screen.
How they are achieving this? Suggest any correct method (industry standard) to do this in React and what is the benefit of this?
Thanks in advance.
Tried to find it by myself but there is not a single article present about this.
4
Answers
Google also does this as well in google.com.
They use the User Agent String of the device and serve a different website
depending on its value.
You can test that yourself using the browser devtools.
First open devtools with
Ctrl + Shift + I
orF12
,then click the 3 dots -> More tools -> Network conditions.
Now you will see the tab
Network conditions
.You can now use your custom User Agent String or select one of the provided there.
If you select a mobile User Agent and then reload,
the website will change to the mobile version.
I check it and I find out something. the meta tag appears if it’s on a phone or the size of the screen is like a phone. so do this resize the page size then refresh the page then check the meta element.
There could be several reasons why some websites do not use the meta name="viewport" tag, such as:
However, the fact that some big brands like Amazon, Zomato, and Swiggy do not use it in their websites does not necessarily mean that it is not important or that it should not be used.
It is worth noting that the absence of the meta name="viewport" tag may lead to issues with the display of web pages on mobile devices, such as content not fitting on the screen, text being too small or too large, and the need for users to zoom in or out to read the content. (as you have already witnessed)
The meta tag adds to the
head
whenever we need it.To do it in React project, you can use useEffect in the App file because we need that useEffect to run every time someone opens the website.
or you can use the
Helmet
package.you can check if the viewport is smaller than something like 765px then the device is a Phone.