Display name
Display name

Reputation: 926

Removing collected static files

I ran collectstatic a few weeks back and I would like to remove most (99.5%) of the collected files so that I do not have to store them when deploying to production. I tried collectstatic --clear but this removed them and then placed the deleted files back afterwards (not sure what the practical point of the command is. The docs state it is used to "to remove stale static files" but it certainly doesn't do that). Is there a way to erase the collected files?

I've been using this page of the Django docs to try and find a solution but haven't had any luck.

Upvotes: 8

Views: 10626

Answers (2)

Display name
Display name

Reputation: 926

It took an interesting combination of commands and actions to get the job done. After replacing my static folder with a new folder with only my desired contents, the base command of

collectstatic --noinput --clear --no-post-process

got most of the files to be cleared and not re-copied. However, the js and css files were still being copied. To get the system to ignore these files and not copy them I used the --ignore tag for each JS and CSS filled-folder that was being copied over. For me personally, this additional command looked like this:

--ignore facebook --ignore gis

In the end the full command pattern for another user would look something like this:

collectstatic --noinput --clear --no-post-process --ignore [JSfolder0] --ignore [JSfolder1] --ignore [JSfolder2]

Upvotes: 9

Branko Radojevic
Branko Radojevic

Reputation: 667

Why don't you simply delete the static folder contents and re-create it with collectstatic? It should gather only updated files. Do your backups before that and you can also compare old and new folder content if it has decreased.

Upvotes: 5

Related Questions