Loading charset using yepnope.js

280 views Asked by At

Is there a way to inject charset: "utf-8" to yepnope using load method without using yepnope.injectJs method

yepnope({
         load: newResourcesToBeLoaded,
         complete: function() {
                   addNewlyLoadedResources(newResourcesToBeLoaded);
                   completeCallback();
         }
});
1

There are 1 answers

0
spiralx On

Not easily, but you can use a filter to do it:

yepnope.addFilter(function (resourceObj) {
  if (resourceObj.url.slice(-3) == ".js") {
    resourceObj.attrs = resourceObj.attrs || {};
    resourceObj.attrs["charset"] = "UTF-8";
  }
  return resourceObj;
});

If you're having any of the issues I had though this won't help, scripts without the charset attribute should pick up the document's charset (from Content-Type header or <meta charset> tag) anyway. There are problems in some browsers when loading UTF-8 encoded files with a BOM (byte order mark) defined, Firefox notably for me.

Also, yepnope.js attempts to load scripts in non-IE/Opera browsers as tags apparently, this was the source of all my issues and eventually made me change to LABjs instead.