Showing posts with label Script. Show all posts
Showing posts with label Script. Show all posts

Friday, June 25, 2010

script标签中的defer属性说明

script中的defer属性默认情况下是false的,其主要作用是为了提升页面性能,实际在目前的HTML 4.0中这个属性是个鸡肋,在各浏览器中表现也不一样,最好忽略此属性。

微软MSDN中的文档说明摘录部分内容如下:
Remarks: Using the attribute at design time can improve the download performance of a page because the browser does not need to parse and execute the script and can continue downloading and parsing the page instead.
Standards Information: This property is defined in HTML 4.0 World Wide Web link and is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 World Wide Web link.

W3C中的说明摘录部分内容如下:
defer [CI]
When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering.
指示脚本不会生成任何的文档内容(不要在其中使用document.write命令,不要在defer型脚本程序段中包括任何立即执行脚本要使用的全局变量或者函数),浏览器可以继续解析并绘制页面。但是defer的script在什么时候执行,执行顺序情况并无明确规定。

正在制定的HTML5有极大可能会完善script标签的定义,这里有简单的HTML5中defer属性的定义和用法

async和defer二个属性属性与src属性一起使用,async定义脚本是否异步执行。
如果 async 属性为 true,则脚本会相对于文档的其余部分异步执行,这样脚本会可以在页面继续解析的过程中来执行。
如果 async 属性为 false,而 defer 属性为 true,则脚本会在页面完成解析时得到执行。
如果 async 和 defer 属性均为 false,那么脚本会立即执行,页面会在脚本执行完毕继续解析。

The async and defer attributes are boolean attributes that indicate how the script should be executed.

There are three possible modes that can be selected using these attributes. If the async attribute is present, then the script will be executed asynchronously, as soon as it is available. If the async attribute is not present but the defer attribute is present, then the script is executed when the page has finished parsing. If neither attribute is present, then the script is fetched and executed immediately, before the user agent continues parsing the page. The exact processing details for these attributes are described below.

The defer attribute may be specified even if the async attribute is specified, to cause legacy Web browsers that only support defer (and not async) to fall back to the defer behavior instead of the synchronous blocking behavior that is the default.

If one or both of the defer and async attributes are specified, the src attribute must also be specified.

Wednesday, May 21, 2008

ruby script/server lighttpd

在一个jruby on rails目录下面运行以下命令时报错:
$> ruby script/server lighttpd
.....
Couldn't find any pid file in '/Users/yu/Sites/RubyOnRails/tmp/pids' matching 'dispatch.[0-9]*.pid'
(also looked for processes matching "/Users/yu/Sites/RubyOnRails/public/dispatch.fcgi")
在lighttpd的log中看到如下信息:
2008-05-21 00:23:33: (log.c.75) server started
2008-05-21 00:23:33: (mod_fastcgi.c.1029) the fastcgi-backend /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi failed to start:
2008-05-21 00:23:33: (mod_fastcgi.c.1033) child exited with status 9 /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi
2008-05-21 00:23:33: (mod_fastcgi.c.1036) If you're trying to run PHP as a FastCGI backend, make sure you're using the FastCGI-enabled version.
You can find out if it is the right one by executing 'php -v' and it should display '(cgi-fcgi)' in the output, NOT '(cgi)' NOR '(cli)'.
For more information, check http://trac.lighttpd.net/trac/wiki/Docs%3AModFastCGI#preparing-php-as-a-fastcgi-programIf this is PHP on Gentoo, add 'fastcgi' to the USE flags.
2008-05-21 00:23:33: (mod_fastcgi.c.1340) [ERROR]: spawning fcgi failed.
2008-05-21 00:23:33: (server.c.908) Configuration of plugins failed. Going down.

经google后才发觉script/server lighttpd只能用于ruby on rails的项目上,通过以下命令:
$> /usr/local/lighttpd/bin/spawn-fcgi -f /Users/yu/Sites/RubyOnRails/public/dispatch.fcgi -p 12000 -s /tmp/rails-fcgi.socket
会得到成功的结果如下:
spawn-fcgi.c.197: child spawned successfully: PID: 2275
而在jruby的项目下调用spawn-fcgi则会报脚本错误。

另附dispatch.sh[reference: http://www.javaeye.com/topic/168989]


#!/bin/sh

DISPATCH_PATH=/Users/yu/Sites/cv2/public/dispatch.fcgi
SOCKET_PATH=//Users/yu/Sites/cv2/tmp/sockets
RAILS_ENV=developement
export RAILS_ENV

case "$1" in

start)
for num in 0 1 2
do
/Users/yu/Programs/lighttpd/bin/spawn-fcgi -f $DISPATCH_PATH -s $SOCKET_PATH/rails.socket-$num
done
;;

stop)
killall -9 dispatch.fcgi
;;

restart)
$0 stop
$0 start
;;

*)
echo "Usage: dispatch.sh {start|stop|restart}"
;;

esac

exit 0

Thursday, May 31, 2007

网站检查脚本


LOOP=0
VART=0
DEST="www.google.cn"
OWGT="192.168.0.1"
USERS="test@test.com"
MSG="Cannot connect to google.cn."
VAR2=`ping -s 1 -c 1 $OWGT > /dev/null; echo $?`
if [ $VAR2 -eq 0 ]
then
while [ $LOOP -lt 11 ]
do
if [ $VART -eq 10 ]
then
VART=0
echo $MSG > /root/msg.txt
mail -s "Cannot connect to google.cn" $USERS < /root/msg.txt
else
VAR1=`ping -s 1 -c 1 $DEST > /dev/null; echo $?`
if [ $VAR1 -ne 0 ]
then
VART=$(($VART+1))
else
VART=0
fi
fi
LOOP=$(($LOOP+1))
done
fi

配合crontab执行,检查网站是否能连接上,如果无法连接则通知网管。
这个脚本实际使用还是需要调整,应该是用wget/curl等检查网站的状态,有的网站会禁ping或者ping久了封IP的。

Wednesday, May 30, 2007

rails script/console problem on ubuntu

shell> ruby script/console
Loading development environment.

/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require':

no such file to load -- readline (LoadError)

from /usr/local/lib/ruby/1.8/irb/completion.rb:10

from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules'

from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules'

from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup'

from /usr/local/lib/ruby/1.8/irb.rb:54:in `start'

from /usr/local/bin/irb:13

Check them out:
http://ubuntuforums.org/showthread.php?t=169891
http://blog.nanorails.com/articles/2006/03/06/installing-readline-on-kubuntu

1.) Download ruby source.
Download Here
2.) Extract the tar file.
tar -xvf ruby-1.8.5-p12.tar.gz
3.) Change to that directory
cd ruby-1.8.5-p12.tar.gz
4.) Type these commands.
./configure
make
sudo make install
5.) Install readline and ncurses.
apt-get install libncurses5-dev libreadline5-dev
6.) go back to the folder ruby source folder.
ruby-1.8.5-p12.tar.gz
7.) Type these commands
cd ext
cd readline
ruby extconf.rb
make
sudo make install

Thats it. The console bug no longer appears.