rgrove/lazyload — Issue #8: add custom charset support
Author: ZhikuanLin
Created: 2011-10-13 06:40:07+00:00
State: open

lazyload is a very good product,
we are going to use it in chinese environment now, but it only supports utf8 charset when loading js/css files.
i know that utf8 is the best choice, but in our sites there is lots of old js/css files using non-unicode charsets such as gbk, gb2312, etc.
so i suggest to add custom charset support:

LazyLoad.js(['file1.js[charset=utf-8]', 'file2.js[charset=gbk]']);
or

LazyLoad.js([{
src: 'file1.js'
charset: 'utf-8'
}, {
src: 'file2.js',
charset: 'gbk'
}]);
Either one would be fine.

and here is the code for the first form:

// lazyload.js 2.0.3
// line 218 add:
var charset = '';
var match = url.match(/\[charset=([a-zA-Z0-9-]+)\]$/);
if (match) {
charset = match[1];
url = url.replace(match[0], '');
}
// line 230 change to:
if (charset != '') node.setAttribute('charset', charset);

Thanks