Way 1: Use Module
I can see this is an unconventional way to keep static files in Media Library but you can try below module if it can help as it performs magnification/bundling of js/css code added in item under nodes you need follow steps written in documentation.
Way 2: You can minify files from your repo
- Install Web Essential in Visual studio.
- After this open repo and add your file over there.
- Right click on js/css file you will get option from web essential to minify the files.
- Then you can upload file in Media library.
You can also add configuration given from below link to web.config file to improve the performance.
However it is not recommended to keep your css and js files in sitecore media library but as you have already decided then you could use SquishIt libraries to bundle and minimize your css and js:
Sample code you need to write in your view file: