[翻译]High Performance JavaScript(029)
Working Around Caching Issues 关于缓存问题
Adequate cache control can really enhance the user experience, but it has a downside: when revving up your application, you want to make sure your users get the latest version of the static content. This is accomplished by renaming static resources whenever they change.
充分利用缓存控制可真正提高用户体验,但它有一个缺点:当应用程序更新之后,你希望确保用户得到静态内容的最新版本。这通过对改动的静态资源进行重命名实现。
Most often, developers add a version or a build number to filenames. Others like to append a checksum. Personally, I like to use a timestamp. This task can be automated using Ant. The following target takes care of renaming JavaScript files by appending a timestamp in the form of yyyyMMddhhmm:
大多情况下,开发者向文件名中添加一个版本号或开发编号。有人喜欢追加一个校验和。个人而言,我更喜欢时间戳。此任务可用Ant自动完成。下面的目标体通过附加一个yyyyMMddhhmm格式的时间戳重名名JavaScript文件:
<target name="js.copy">
<!-- Create the time stamp -->
<tstamp/>
<!-- Rename JavaScript files by appending a time stamp -->
<copy todir="${build.dir}">
<fileset dir="${src.dir}" includes="*.js"/>
<globmapper from="*.js" to="*-${DSTAMP}${TSTAMP}.js"/>
</copy>
</target>
Using a Content Delivery Network 使用内容传递网
A content delivery network (CDN) is a network of computers distributed geographically across the Internet that is responsible for delivering content to end users. The primary reasons for using a CDN are reliability, scalability, and above all, performance. In fact, by serving content from the location closest to the user, CDNs are able to dramatically decrease network latency.
内容传递网络(CDN)是按照地理分布的计算机网络,通过以太网负责向最终用户分
相关文档:
隐藏成员变量
在函数体内定义的变量为局部变量,离开函数就挂掉了
在函数体内使用this.成员变量名,则为window对象级变量,即全局变量
故需要这样隐藏成员变量,向外只暴露get、set函数
function testClass(name){
var _firstname=name;
return {
getname : function() {
return _fir ......
常规的方法是将年月日取出,然后分别判断范围,然后就判断闰年2月的天数
可以通过new Date(string)的构造,比较年月日字符是否发生变化判断。
function CheckDate(text) {
if (!text) return false;
text = text.replace(/[\/-]0?/g, "/");
if (!text.match(/^\d{4}\/\d{1,2}\/\d{1,2}$/)) return true;
......
function total(){
var i=0;
for(j=1;j<=20;j++)
{
var step="step"+j;
if(document.getElementById(step)){
if(document.getElementById(step).checked==true)
{
i=i+parseInt(document.getElementById(step).value);
}
}
}
document.getElementById("total").innerHTML = i;
}
function Resetvalue(){
......
A Note on Benchmarking 测试基准说明
Because a regex's performance can be wildly different depending on the text it's applied to, there's no straightforward way to benchmark regexes against each other. For the best result, you need to benchmark your regexes on test strings o ......
第八章 Programming Practices 编程实践
Every programming language has pain points and inefficient patterns that develop over time. The appearance of these traits occurs as people migrate to the language and start pushing its boundaries. Since 2005, when the term "Ajax" ......