简体   繁体   English

jQuery / Javascript —如何在视觉上优化我的网站负载?

[英]Jquery / Javascript — How to optimise my site load visually?

I'm making finishing touches on my site and am struggling to make the load of the page look less jumpy. 我正在对我的网站进行最后的润色,并且正在努力使页面的负载看起来不那么波动。 best way to show you what i mean is to show the site: http://marckremers.com/2011 (Still not complete, in alpha phase) 向您展示我的意思的最佳方法是向您展示该网站: http : //marckremers.com/2011 (仍未完成,处于Alpha阶段)

As you can see the contents sticks to the left, loads a ton of jquery and images into the page, and only then click into place (centre). 如您所见,内容停留在左侧,将大量的jQuery和图像加载到页面中,然后单击到位(中心)。

I'm wondering if there is a way i can make it click into place first and then load the elements? 我想知道是否有一种方法可以使其首先单击就位,然后加载元素?

I tried putting the reposition script just after , not even that works. 我尝试将重定位脚本放在之后,甚至无法正常工作。

Any ideas? 有任何想法吗? Thanks 谢谢

With all of the images you have, your page is 1.5mb , coupled with 70 http requests. 使用所有图像,您的页面大小为1.5mb ,并带有70个 http请求。 No wonder your site behaves the way it does. 难怪您的网站会表现出它的行为方式。

You should be using sprites on the smaller images to reduce http requests and as far as the large images go, you are loading all of the pictures at once. 您应该在较小的图像上使用Sprite来减少http请求,而就较大的图像而言,您要一次加载所有图片。 Even the ones that aren't displayed right away. 即使是没有立即显示的内容。 The images that aren't displayed right away should be pulled in via AJAX after the page loads. 页面加载后,未立即显示的图像应通过AJAX提取。

If you want to go further into optimization I would also: 如果您想进一步优化,我也会:

  • Use one external javascript file. 使用一个外部javascript文件。 Yes it increases size, but I favor that over http requests. 是的,它增加了大小,但我偏爱于HTTP请求。
  • Minify your html/javascript/css. 缩小您的html / javascript / css。
  • Don't host jQuery on your site, use a CDN such as Google APIS . 不要在您的网站上托管jQuery,请使用CDN(例如Google APIS)
  • Check out a service similiar to Amazon S3. 签出与Amazon S3类似的服务。

I could reinvent the web site best practices wheel here, or I could send you to Yahoo best practices for web site optimization There is a ton of very important information there, read it and reference it. 我可以在此处重塑网站最佳实践,也可以将其发送给Yahoo最佳实践进行网站优化。那里有大量非常重要的信息,请阅读并参考。

You loaded jQuery twice, once from your own site and another time from Google's CDN. 您两次加载了jQuery,一次是从您自己的网站加载的,另一次是从Google的CDN加载的。 For starters, you should probably move all the JavaScript to the bottom of your HTML. 首先,您可能应该将所有JavaScript移到HTML的底部。 Then you need to optimize your if ... else that handles how many columns to display and your Google Maps iframe. 然后,您需要优化if ... else来处理要显示的列数和Google Maps iframe。

To speed the visual up, instead of using jQuery, you should probably have some vanilla DOM scripting that dynamically creates some CSS styles for the projects and tb_tweets classes, so it doesn't have to wait for all your JavaScript to load before handling resizing of your projects and tb_tweets . 为了加快视觉效果,您可能应该使用一些普通的DOM脚本来动态地为projectstb_tweets类创建一些CSS样式,而不是使用jQuery,因此不必在处理所有大小的JavaScript之前就对其进行调整。您的projectstb_tweets

use http://mir.aculo.us/dom-monster/ and do everything it tells you to do. 使用http://mir.aculo.us/dom-monster/并按照提示操作。 If you want tools to figure out what is going on during page load, the chrome developer tools are hands down the best out there for client side optimization. 如果您想让工具找出页面加载期间发生的情况,那么chrome开发人员工具可以帮助您进行最佳的客户端优化。

A think you could do is put your javascript functions in the document.ready(function()), this way the functions will be loaded AFTER the page is loaded. 您可以做的是将javascript函数放在document.ready(function())中,这样可以在页面加载后加载这些函数。 I guess you don't need the functions for loading the site, just to interact with it? 我猜您不需要加载网站的功能,仅需与之交互即可?

Generally you only want to trigger your events after the page has rendered, ie, using 通常,您只想在页面呈现后触发事件,即使用

$(document).ready(function()) {
   //your javascript goes here
}

Then, in your HTML you have placeholders so the page doesn't "expand" or "jump" as you put, with some kind of indication that the element is still loading. 然后,在您的HTML中有占位符,因此页面不会像您放置的那样“扩展”或“跳转”,并带有某种指示,表明该元素仍在加载中。 Then, when your ajax requests complete, simply populate the placeholders with the ajax response. 然后,当您的ajax请求完成时,只需使用ajax响应填充占位符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM