ngryman/badge-size

Ability to read from NPM

treshugart opened this issue ยท 11 comments

I really like your idea, but my issue is that we don't commit our dist/ files. I was wondering if there was a way to read a file from NPM where the dist/ is published on release?

I like the idea to read from npm, as in theory, dist files should only be published there, not on git.

I see 3 things that make me doubt about implementing it.

We have to download the whole package tarball and extract it (issue)

That annoys me as the current implementation of badge-size is kind of dumb: it fetches a file via http and compute size on demand (and use github proxy cache), but still.
If I add support for npm, I need custom logic and some kind of webhook / storage development to update / store the size of a given file.

It becomes package manager dependent

What is interesting now, is that any kind of file, using any kind of package manager can be processed. This is dumb, this is simple, and I like it that way.
If I add npm specific support, then bower users will want support, and so on. I would like to keep it really KISS.

Is it a common use case?

I agree that it should be done that way, but I'm under the impression that most people don't follow this practice and simply put their dist files on github for the sake of simplicity and to let the possibility to download them directly. And as said before, not every front-end library authors use npm.


IMHO badge-size should not care on how to fetch a file. That's why I'm thinking about 2 things:

  • I could add support for any url, not only github specific. It would allow to fetch a file from anywhere as long as it's http.
  • I could develop another service which goal would simply be to expose a given npm file through http. You could use it with badge-size for your use case, or even create a badge-size-npm package to bundle this.

What do you think?

I definitely think you should keep it simple. I'll admit I overlooked the complexities of using NPM. Your URL suggestion gives you the best of all worlds because you can just point it to a CDN such as https://npmcdn.com or https://rawgit.com.

I didn't knew about https://npmcdn.com, that's perfect I guess ๐Ÿป.
I'll add any url support shortly.

Hey @ngryman, just wondering if you have an ETA on when this will be released? Thanks again for enabling this :)

Hey @treshugart, yes sorry I've been busy last week. Also I switched to micro instead of hapi and brought back redirections instead of proxying requests.
That's a big changeset, so I wanted to be sure that everything work as expected.

My main concern is that github caches images and raw content. I want to be sure that the badge gets refreshed in a decent amount of time. From what I've tested, it gets refreshed every 5mins because of raw content cache, which is perfectly fine to me.

Could you confirm that you have the same behavior your side? You can test it here: https://badge-size-staging.herokuapp.com.

If everything is ok for you then I'll push the new version.

Thanks!

Seems to work fine. I can't confirm the cache expiry time yet, though, but I think you're right.

@treshugart That's deployed!
Btw you can use img.badgesize.io if you want, but without ssl ๐Ÿ˜‰.

Hi guys!
What's wrong in this badge? Seems to be don't work...
I don't understand if the features is already deployed...

http://img.badgesize.io/https://npmcdn.com/fresh-js/dist/Fresh.min.js.svg?compression=gzip&style=flat-square

Thanks!

Thankyou @ngryman, amazing work!

I opened a PR to add this to the docs

#49