Web应用优化技巧
作者:Fenng|可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明 Flickr是 Web 2.0 的代表站点。面对的网络问题除了一般 Web 站点都会有的内容优化之外, 还有必须要灵活处理 JavaScript 与CSS的频繁变化后部署分发带来的复杂性。 设定文件大小的策略首先面临的一个问题是把所有的 JavaScript 与CSS放到一个文件中好呢,还是分割成多个文件 ? 从减少网络请求的角度上考虑, 前者更好,后者差。但是从并行的角度考虑,IE与 Firefox 默认情况下都只能同时从一个域请求两个资源. 这会在很多情况下给用户带来不良的使用体验--必须所有的文件都下载完毕才可以看到像样的页面. Flickr 采用了折衷的办法--在保持文件数量尽可能少的情况下,把 JavaScript 与CSS分成多个子文件. 这在开发上带来了复杂性,但是对性能的收益是巨大的。 压缩的优化问题毫无疑问,对站点内容进行压缩是一个比较常用的 Web 优化手段.但是并不一定都能达到理想的效果.原因在于mod-gzip模块不但消耗服务器端CPU资源,也消耗客户端CPU资源. 而且, mod_gzip 压缩文件后创建的临时文件是放到磁盘上的,这也会给磁盘IO带来严重的问题. Flickr 采用的是 Httpd 2.x 以后支持的 mod_deflate模块.压缩操作都在内存中进行.mod_deflate 在 Httpd 1.x 是不可用的, 不过可以通过创建RAM盘的方式来间接提高性能. 当然, mod_gzip 到也不是一无是处, 对于预压缩的文件, 还是有好处的. 而且, 采用压缩的时候,也要注意策略. 图片文件压缩就没什么必要了(Flickr 上图像多, 而且压缩得不到什么好处). Flickr 只对 JavaScript 和CSS进行压缩. mod_gzip 新一点的版本能够自动通过配置 mod_gzip_update_static 选项自动处理 预压缩的文件. Cal 也指出这个特性在一些旧版本的浏览器上会出问题. 压缩的另一个主要手段是内容的压缩. 针对 JavaScript 可以进行通过减少注释、合并空格、使用紧凑的语法等小技巧(Google 的所有脚本都非常难读,而且非常紧凑,思想类似).当然,经过这样处理的 JavaScript 可能带了很多括号不容易解析,Flickr使用了Dojo Compressor来构建解析树。Dojo Compressor 开销很低,而且对于最终用户是透明的. JavaScript 的处理方法介绍过,CSS 处理则相对简单.通过简单的正则表达式替换(比如把多个空格替换为一个空格符), 最高可以获得 50% 的压缩比。 Caching 的优化Flickr的开发者充分利用了 Http 1.1 规范定义的Etag 与 Last-Modified 机制来提高 Caching 的效率. 值得注意的是,Cal 介绍了一个在负载均衡条件下的 e-Tag 小技巧. 即可以设定 Apache 通过文件调整时间与文件大小获得 E-Tag ,而默认情况下, Apache 是通过文件节点获取 e-Tag 的。当然,这也不是很完美,因为会影响 if-modified-since 。 灵活运用 mod_rewrite据说Flickr网站应用是进行每日构建的(Daily Build)。 如果没有一个灵活的机制恐怕这是不可想象的。而且,在 Flickr 这样的站点, 内容的修改同步的处理都是很让人头疼的难题. 他们的利器是mod_rewrite的灵活运用。通过配置URL重写规则,很容易切换到不同的环境下。听起来很简单, 但是没有一定的 Web 技术功力谈何容易做到 ?! 通过这几个主要方法的运用,我们看到了如梦幻一般高性能的Flickr. --End. 这篇 【Flickr 的开发者的 Web 应用优化技巧】来自dbanotes.net
网址:http://www.dbanotes.net/web/flickr_web_tech.html
Cal Henderson 是大名鼎鼎的Flickr网站的开发者之一.在一篇名为Serving JavaScript Fast的文章中,他介绍了用于 Flickr 站点应用优化的技巧,读罢感觉获益良多."嚼一下别人的馍",概括一下该文的主要内容.
BTW: 因为在 Flickr 在国内没有服务器, 大陆用户访问的速度就别提了 :(

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Deleted something important from your home screen and trying to get it back? You can put app icons back on the screen in a variety of ways. We have discussed all the methods you can follow and put the app icon back on the home screen. How to Undo Remove from Home Screen in iPhone As we mentioned before, there are several ways to restore this change on iPhone. Method 1 – Replace App Icon in App Library You can place an app icon on your home screen directly from the App Library. Step 1 – Swipe sideways to find all apps in the app library. Step 2 – Find the app icon you deleted earlier. Step 3 – Simply drag the app icon from the main library to the correct location on the home screen. This is the application diagram

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

Time complexity measures the execution time of an algorithm relative to the size of the input. Tips for reducing the time complexity of C++ programs include: choosing appropriate containers (such as vector, list) to optimize data storage and management. Utilize efficient algorithms such as quick sort to reduce computation time. Eliminate multiple operations to reduce double counting. Use conditional branches to avoid unnecessary calculations. Optimize linear search by using faster algorithms such as binary search.

Win11 tricks revealed: How to bypass Microsoft account login Recently, Microsoft launched a new operating system Windows11, which has attracted widespread attention. Compared with previous versions, Windows 11 has made many new adjustments in terms of interface design and functional improvements, but it has also caused some controversy. The most eye-catching point is that it forces users to log in to the system with a Microsoft account. For some users, they may be more accustomed to logging in with a local account and are unwilling to bind their personal information to a Microsoft account.

The Go language is an open source programming language developed by Google and first released in 2007. It is designed to be a simple, easy-to-learn, efficient, and highly concurrency language, and is favored by more and more developers. This article will explore the advantages of Go language, introduce some application scenarios suitable for Go language, and give specific code examples. Advantages: Strong concurrency: Go language has built-in support for lightweight threads-goroutine, which can easily implement concurrent programming. Goroutin can be started by using the go keyword

Go builds interactive web applications that run in the browser. Steps: Create Go project and main.go file, add HTTP handler to display messages. Add forms using HTML and JavaScript for user input and submission. Add handling of POST requests in your Go application, receive user messages and return responses. Use FetchAPI to send POST requests and handle server responses.

Title: PHP replacement skills revealed! PHP, as a popular server-side scripting language, is often used to handle data replacement and manipulation. In daily development, we often encounter situations where strings need to be replaced. This article will reveal some commonly used replacement techniques in PHP and give specific code examples to help readers better master these techniques. 1. Use the str_replace() function The str_replace() function is one of the most commonly used string replacement functions in PHP. it can
