![]() If you run into this, whitenoise is a very nice library that will serve your static files through Django. A function that minifies your javascript or css files, and all the javascript or css files in your nested folders as well. It provides you with the template tag compress, which you use like this: ĭeploying static files to production can be a bit of a hassle. Install npm i minify-all-js Repository /adonespitogo/node-minify-all-js Homepage /adonespitogo/node-minify-all-jsreadme Weekly Downloads 1,434 Version 0.1.9 License MIT Unpacked Size 5. It can combine JS and CSS files (respectively, of course, we’re not monsters!), and can also process SASS/LESS markup while it’s doing so. Compressionĭjango-compressor is pretty much what you are looking for in most cases, I think. On the other hand, I have no dependency on Node.js at all, which is especially nice when your project is used by many other people, and there’s no need to learn how to write Webpack configs (which can have an infinite degree of complexity). This is a considerable disadvantage, to my mind. I don’t get the luxury of automatic updates, by pinning versions etc. Hello I'm using uglifyJs to minify my javascript files, it's working well with one file at a time, what I'm loking for is to minify all the javascript files present in a folder called JS into a folder called JSM, to be clear I have 2 files inside my JS folder called test1.js and test2.js and I want to run uglify against that folder and generate. This has a very noticeable number of drawbacks: I have to do updates the same way, by copying files in manually. ![]() Typically I put both the minified and the non-minified file there, and decide depending on settings.DEBUG which version to serve.You can see one example for this setup here. I put the vendored files there by hand (most projects offer a finished bundled version for this purpose, often from a CDN for ready use). ![]() All of these will have subdirectories called js, css, and possibly assets (for images etc). For example, if scripts/ contains a.js and b. js files in the scripts directory one level deep. Additionally I’ll have a vendored directory for all JavaScript/CSS dependencies. Yes, thats correct if you only want to concatenate and minify all. Within my /static/ directory, I’ll have subdirectories by app, if that makes sense for your projects (ie if you actually have and use mutiple apps), or just one directory with my project’s name. folder (js and scripts are popular names) see Organizing Files in Chapter 2. Frontend-heavy projects often use a setup as Leigh described, and I just want to add a version that I often use in smaller/less frontend-heavy projects: Structure If you don’t need that complexity, there are other solutions that can be installed with Pip (or poetry or pipenv) and integrated directly into Django’s static asset management is definitely right that there is no one blessed approach, and there is a wild variety of ways to handle static files out there. The Webpack approach is more or less infinitely flexible, but also rather complex (configuring Webpack is something you could write an entire book on, and it requires you to have Node.js available at build time). The webpack config we use for some things at work is on GitHub here, but I don’t really get loads of time to make these sorts of things consumable by people outside the company, so I wouldn’t use it wholesale. We then use django-webpack-loader to actually load the entry points into our templates, so that Django can find the right hashed file name. Minify your JavaScript files online by pasting some JavaScript code into the text area below. I use AWS amplify for a site and have that along with some other stuff minifying things, here is my package.json file.To my knowledge at least, there isn’t a blessed One True Way to manage static files in Django, but rather lots of different ways with different advantages and drawbacks.Īt my work, we use Webpack (and an assortment of plugins) to build TypeScript and Sass into JS and CSS, bundle it, minify it, and add cache-busting hashes to the file names. ![]() Not sure about the comments, that is probably an option. Or Gulp tasks can do the same type of thing. You can use a node package to do it - html-minifier.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |