Skip to content
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

Swashbuckle assets need compression and minification #467

Closed
centur opened this issue Aug 22, 2015 · 5 comments
Closed

Swashbuckle assets need compression and minification #467

centur opened this issue Aug 22, 2015 · 5 comments
Milestone

Comments

@centur
Copy link

centur commented Aug 22, 2015

Javascript and css assets, that are part of SwaggerUI need minification and compression (as in Swashbuckle.Core.5.2.1).
E.g.

GET /swagger/ui/swagger-ui-js - 1.5Mb Unminified uncompressed

Downloading 1.5 Mb of javascript everytime when opening Swagger UI is not the best experience.
Also as it is extension-less asset - it not being cached properly by client browsers.

I tried to add GZip compression using Global filter in webapi pipeline, but seems that Swashbuckle somehow ignores global setup.
It'd be nice to enable some way to configure filters for /swagger route so we can protect this UI it with basic auth, add compression and modify some behaviour if needed (main idea is to protect UI with auth and add compression to outputs)

@daward
Copy link

daward commented Aug 26, 2015

I too have this problem, it makes this version of swashbuckle nearly unusable and should be a pretty minor change to use minified version.

@centur
Copy link
Author

centur commented Aug 27, 2015

I wrote a middleware that minifies everything what comes from /swagger url but it needs some extra work to function properly - somehow it messes up with api responses in SwaggerUI

@domaindrivendev
Copy link
Owner

@centur - I was going to suggest a DelegatingHandler (see http://www.asp.net/web-api/overview/advanced/http-message-handlers) for intercepting the swagger request and applying additional customization (authorization, compression etc.). Of course if you're using OWIN, you could achieve the same result with middleware.

@daward - For the next release, I'll update the swagger-ui index.html served up by SB to reference the minified version of swagger-ui.js. In the meantime though, you could achieve the same thing by injecting your own version (copied from https://github.com/domaindrivendev/Swashbuckle/blob/v5.2.1/Swashbuckle.Core/SwaggerUi/CustomAssets/index.html) with the modified reference. See the readme for details - https://github.com/domaindrivendev/Swashbuckle#provide-your-own-index-file.

On a final note, I switched to extension-less URL's to avoid the need for setting runAllManagedModulesForAllRequests and hence the associated perf. concerns. I hadn't anticipated that browsers would not cache assets as a result and that's an unfortunate side effect.

It's worth noting that extensionless URL's will not be used in the next major version (which will be 6.0.0), targeting AspNet 6.0.

@centur
Copy link
Author

centur commented Sep 21, 2015

Just in case anyone wants it now - here is the simple gzip middleware that compresses js and css on the fly (OWIN based)

@domaindrivendev
Copy link
Owner

Using minified swagger-ui in v5.2.2 - now available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants