rgrove / lazyload

:skull: An ancient tiny JS and CSS loader from the days before everyone had written one. Unmaintained.
MIT License
1.39k stars 288 forks source link

add custom charset support #8

Open zhikuanlin opened 13 years ago

zhikuanlin commented 13 years ago

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

zhikuanlin commented 12 years ago

code above has a bug, "charset" must be set to the newly created node before "src", see: http://yuilibrary.com/projects/yui3/ticket/2528363

tylerzhu commented 12 years ago

Is the problem solved?