[英]How to make responsive web page render faster?
Right now, every time I try to render a page, I will calculate the $(window).width()
first and then add a corresponding class for the root html
element, which will final determine the block width of some main responsive elements in the page. 现在,每次我尝试渲染页面时,我都会首先计算
$(window).width()
然后为root html
元素添加一个相应的类,这将最终确定一些主要响应元素的块宽度。这一页。 But this approach goes with a problem. 但这种方法存在问题。 It will first render the page with a initial default width, and then after the class is added, it will adjust the element width, which will create a non-smooth visual effect.
它将首先使用初始默认宽度渲染页面,然后在添加类之后,它将调整元素宽度,这将创建不平滑的视觉效果。
To overcome this, I then make all the responsive elements display: none
in the first place and make them visible after the width calculation is done. 为了解决这个问题,我然后让所有响应元素
display: none
首先display: none
,并在宽度计算完成后使它们可见。 But for a user, it takes more time to see the page in this way. 但对于用户来说,以这种方式查看页面需要更多时间。
So I was wondering if there is a way to achieve this responsive page in a more efficient and faster way? 所以我想知道是否有办法以更有效和更快的方式实现这个响应式页面?
If you are using javascript
to create a responsive site, there are much easier ways. 如果您使用
javascript
创建响应式网站,则有更简单的方法。
For example, there are TONS of free CSS
based frameworks you can utilize to make responsive pages that the CSS
controls, which doesn't eat up nearly as many resources as a javascript
solution. 例如,有免费吨
CSS
基础框架,你可以利用做出响应页面的CSS
控制,这也不吃了几乎同样多的资源作为一个javascript
解决方案。 Lots of DOM
manipulation with javascript
can get pretty hairy pretty quickly. 使用
javascript
进行大量DOM
操作可以很快得到很好的毛利。
My suggestion would be to look into some of the following: 我的建议是研究以下几点:
I personally use foundation
for my development, as its easy to read/understand and it produces rapid development. 我个人使用
foundation
进行开发,因为它易于阅读/理解,并且可以快速开发。
Example: http://www.sinsysonline.com/secondhomehostel 示例: http : //www.sinsysonline.com/secondhomehostel
If you are ABSOLUTELY dead set on having Javascript
handle your DOM
rendering, it's going to be much slower than a CSS responsive
site. 如果你绝对没有使用
Javascript
处理你的DOM
渲染,那么它将比CSS responsive
站点慢得多。
If so, try out: 如果是这样,请尝试:
If you would like further clarification for a specific problem, could you please provide your code and I'm more than happy to provide some feedback on that. 如果您想进一步澄清具体问题,请提供您的代码,我非常乐意提供一些反馈意见。
CSS media queries allow you to apply CSS based on screen size. CSS媒体查询允许您根据屏幕大小应用CSS。 The advantages of this over your approach are:
这种方法优于您的方法:
1) The CSS will read the window size immediately 1)CSS将立即读取窗口大小
2) The page will automatically adjust if the user resizes the window (or rotates their tablet) 2)如果用户调整窗口大小(或旋转平板电脑),页面将自动调整
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
You need to use css3 media queries which is very useful to create responsive website. 您需要使用css3媒体查询,这对创建响应式网站非常有用。 You need to write css according to viewport width.
您需要根据视口宽度编写css。 Please refer the link from which you will get all the idea about responsive website.
请参阅链接 ,您将从中获得有关响应式网站的所有想法。
I hope this will help yo to work on the responsive websites. 我希望这有助于您在响应式网站上工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.