-
-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to generate bundle including subset of keywords #460
Comments
@seeden I'm not sure how Ajv can be split... Theoretically keywords can be plugins and optional, but I'm not sure I like this idea. In any case it is not related to using ES6. For your application a better idea could be to precompile your schemas into modules using ajv-cli (that uses ajv-pack inside). It may result in a smaller bundle size (depending on the number and the size of schemas) as only a small portion of Ajv will be included in the compiled code. |
@epoberezkin I am generating schemas on demand because they are dynamic |
You can also try using some build tools that remove unused code - e.g. if there are some Ajv methods/functions you don't use they can be removed. It requires bundling Ajv together with your app, but it's easier than managing manually what should and shouldn't be included. |
I am using webpack 2 (modules false) with uglify as well. But as I told the final size is 196kb / 35kb minified gziped version. |
196kb not minified? If so, you already remove 25%. That should reduce the bundle substantially. |
Hi @epoberezkin @seeden I believe we could have the |
Can you please explain? |
My first thought was to remove |
you can precompile your schemas with ajv-cli - the code can be smaller (unless you have large schemas, in which case it can become bigger :), as it will only include used run time parts of ajv and not the compilation logic. |
This is now possible in v7 using AjvCore ( The size reduction is not as substantial as may be expected - Ajv without any keywords is approximately 35% smaller than Ajv with all draft-2019-09 keywords, and 30% smaller than with draft-7 keywords - the big part is the core logic that is required for all keywords. A bigger potential to reduce the size could be to ship with compiled schemas (PR #1332 - in progress), but it depends on the number of schemas - a compiled validation code is bigger than the schema itself - so you have to do this estimation for your application. |
Hi @epoberezkin
I really like ajv. Version 5 is great because I have no problem with webpack as well.
Currently I am trying to reduce bundle size of my projects and ajv took almost 196kb / 35kb minified gziped version.
Did you think about spliting your package? or do it more modular with ES6?
Currently I am using just very simple funcionality from ajv like required properties and min max values.
Thank you for your time
The text was updated successfully, but these errors were encountered: