Comments (14)
& perhaps minify JSON (not sure if the extra whitespace is from browsers' JavaScript-API)?
edit: Basically just don't include \r \n \t \s (if they exist).
from api.
& perhaps minify JSON (not sure if the extra whitespace is from browsers' JavaScript-API)?
Basically just remove \r \n \t \s (if they exist).
I can accept a PR for this. Probably the cleanest way is to implement it as a Connect middleware so you don't need to touch rest.
from api.
Our proxy already gzips it I think.
Minifications should be an extra parameter and by default it should output the clean human version.
What do you think?
from api.
Edit: I goofed! I thought we were talking about the CDN (I had missed that this issue was in the API repo).
I just did a quick check of http://cdn.jsdelivr.net/jquery/2.1.1/jquery.min.js and Live HTTP Headers reports Content-Encoding: gzip
, so yeah, it looks to me like gzip is already working. :)
And by "extra parameter" (for minification), @jimaek, I assume you mean the .min.js
, which I agree is a good way to handle things (and seems pretty standard).
from api.
@EnigmaSolved This is the API repo so we are talking about http://api.jsdelivr.com/v1/jsdelivr/libraries/jquery and not the CDN :)
from api.
@jimaek: Oops--My bad! I came across jsDelivr a month or so ago, and in perusing the Git repos came across the current thread and so held off on doing anything else (since I interpreted gzip was not yet supported), and in the process missed that I was in the API repo (and that gzip is supported for the CDN). Thanks for bearing with my misinformation above! I'm really looking forward to switching to jsDelivr for my website! :)
from api.
extra parameter and by default it should output the clean human version
I'm not sure of any real reason for a human-readable version by default, can you give a use-case please?
& the little usefulness for a toggle to turn on API-based beautification is mostly for us for in-browser testing. People should only look at raw API data when they're developing, & even then not always needed there. Worse comes to worse there are many online JSON beautifiers & tree-viewers.
I can accept a PR for this. Probably the cleanest way is to implement it as a Connect middleware
Thanks, but I don't know Connect currently, sorry. :/ A quick look at your code does not show where you add whitespace, perhaps in res.json
? But that should default to 0 unless still in dev mode? Leaving the last parameter blank in JSON.stringify
prevents whitespace being added.
from api.
A quick look at your code does not show where you add whitespace, perhaps in res.json?
It's the default behavior of res.json
(JSON.stringify). You can configure like this: app.set('json spaces', null);
(no newlines). This is global configuration and doesn't fit this particular case that well.
It is cleanest to implement it as a middleware evaluated at the end of the stack. Simply strip newlines from res there and hit next()
.
from api.
I'm not sure of any real reason for a human-readable version by default, can you give a use-case please?
To simplify the work for the developer. When testing the API he will try opening it himself and see what data is returned with different parameters. And once he is ready to go live he can add the parameter to return minified data.
from api.
Please open a separate issue for the extra parameter and specify what it should look like there. I'll get the feature done.
from api.
To simplify the work for the developer
I get that, but this dev-traffic ideally should only represent only 0.001% of all traffic, right? (Right now is weird since API is still semi-beta.) So the default is for 0.001% & the flag/exception is for 99.999%?
from api.
I get that, but this dev-traffic ideally should only represent only 0.001% of all traffic, right? (Right now is weird since API is still semi-beta.) So the default is for 0.001% & the flag/exception is for 99.999%?
I agree that making the output minified (no \n
's) wouldn't break anything and would save a bit of bandwidth (worth it?).
It would be interesting to know how other APIs deal with the same issue.
from api.
[no whitespace will] save a bit of bandwidth (worth it?).
Some, enough to be worth it for medium to large queries, but not as much as you assume since gzip will tokenize whitespace really well; there are alot of ",\n
, '{\n
etc. Here is a test, not sure if my GZip parameters are the same on your server that I used in 7-zip (normal level, dictionary 32k, Word 32), but here is a test of jsDelivr name=jq* (full jsDelivr dump breaks my computer)
405,190 jsdelivr.jq-splat.src.json
55,298 jsdelivr.jq-splat.src.json.gz
289,494 jsdelivr.jq-splat.min.json
51,182 jsdelivr.jq-splat.min.json.gz
I think the bigger impact will be on server & client resources; smaller files are faster to pack, unpack, process, take less HD space. 1/4 unpacked smaller file size is significant.
It would be interesting to know how other APIs deal with the same issue
CDNJS is whitespaced; d/l it makes my laptop's fans go into turbo.
I discovered a good middle-ground between readable & compressed by removing whitespace around brackets, but leaving newlines around data:
[{
"name":"AngularJS",
"_id":"l1IY4GwpT",
"created":"2014-05-06T06:53:53.685Z",
"mainfile":"angular.min.js",
"homepage":"http://angularjs.org",
"lastversion":"1.3.0-beta.5",
"assets":
[{
"version":"1.3.0-beta.5",
"files":
[
"angular.js",
"angular.min.js"
]},{
"version":"1.3.0-beta.4",
"files":
[
"angular.js",
"angular.min.js"
]},{
"version":"1.3.0-beta.3",
IMHO the normal output should still remove all whitespace, but this semi-minified can be used to save resources for the human-readable dev output. I find this is still eye-scanable, since data is chunked well I can speed-read it. (Actually easier, since I can read down instead of back & forth with indented data.)
from api.
We already do Gzip thanks to MaxCDN that is in front of the API server. I think we can close this.
from api.
Related Issues (20)
- Version sorting HOT 10
- API returns no versions (urgent) HOT 5
- Move the API away from AppFog HOT 8
- Am I right to assume that I cannot get data for multiple librarys with one api call? HOT 4
- Searching by URL HOT 1
- jQuery failed to update latest beta1 HOT 2
- File paths HOT 14
- Incorrect author format for some CDNJS projects HOT 3
- pagination need? HOT 3
- The result order is not right HOT 3
- Default filename for specified version HOT 8
- API is not detecting new projects HOT 2
- Specify Content Security Policy? HOT 1
- API future HOT 3
- Add SRI to API HOT 1
- Add a download/hit count to the API HOT 7
- API endpoint down? HOT 2
- "bootstrap" alias is gone in v1 HOT 7
- Remove X-Requested-With
- Make sure logentries is utilized HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api.