Dojo has got the slowest selectors compared to other JS frameworks.
I was wondering if it was possible to use Sizzle within Dojo to make dojo.query use it behind the scenes? I think it is used in jQuery that way, so it should be possible in Dojo too.
Couldn't find any info about how to do that.
PS The test at the link seems to be being actively developed and changes daily, so make sure you select the latest version on that page.
EDIT: it appeared that the numbers in the test were not correct, and the difference between Dojo and others is not really as radical. That makes the task of including Sizzle into Dojo not worth the effort.
I question your numbers. Others have come to the opposite conclusion about Dojo's query engine. They're all pretty fast, to the point where is probably doesn't make that big a difference.
I don't have a precise answer to this, but it definitely seems possible. According to a dojo ticket this feature has been in the cards for quite a while.
The dojo query documentation has a section called Alternate Selector Engines
with a link to a github repository which appears to have a fairly easy drop in replacement for the dojo query engine.
By performing a custom build of dojo, you can automatically bake in the sizzle engine. If you look at (the source distribution) util/buildscripts/jslib/buildUtil.js
There is a parameter for query
:
"query": {
defaultValue: "default",
helpText: "Select a DOM query engine. Default value is the normal dojo.query engine. Using query=sizzle will use the Sizzle engine."
+ "Normal Dojo tests are not run routinely with the Sizzle engine. See dojo/_base/sizzle.js for the version of Sizzle."
},
You don't need to replace dojo.query with sizzle.
You can say dojo.query, it should use sizzle.
In the dojo config
var dojoConfig = {
selectorEngine: "sizzle",
async: true
};
Use https://github.com/kriszyp/sizzle as you would do with any other dojo package
see http://dojotoolkit.org/reference-guide/1.9/dojo/query.html
来源:https://stackoverflow.com/questions/8063962/replace-dojo-query-with-sizzle