Reputation: 1734
I have read about implementing git hooks to minify css and js source files post-commit (as minified assets shouldn't be committed) but what is the best practice when committing the actual links to these within HTML pages?
The only options I can think of are:
Git commit HTML pages with links to minified source files, but without minified source files in the repository:
<link href="/assets/css/application.min.css" rel="stylesheet">
<script src="/assets/js/application.min.js"></script>
Git commit HTML pages with links to the development source files and change to minified once deployed:
<link href="/assets/css/application.css" rel="stylesheet">
<script src="/assets/js/application.js"></script>
I am sure there is a simple and effective workflow to achieve this that I am unaware of. Many thanks in advance!
Upvotes: 0
Views: 881
Reputation: 1734
I have decided on the route of committing links to minified source files within HTML pages, but without minified source files in the repository. This means that I am relying on an intermediate tool (such as CodeKit) to automatically minify source files for me as I work on the development versions but it is a workflow that is working well for me so far.
Upvotes: 1
Reputation: 16185
For something like this I prefer to put it in a sample config file and commit that instead. During development and deployment that sample config file is copied to its proper name and modified as necessary to fit the requirements. That way you won't have unnecessary modifications to a tracked file for a specific deployment environment.
Example:
# config.conf.sample
main_css = application.min.css
main_js = application.min.js
During development we just copy config.conf.sample to config.conf and modify the entries accordingly:
# config.conf
main_css = application.css
main_js = application.js
And during deployment since the entries matches what we want already a simple copy suffices.
This setup also works well for cases where you don't want to commit config files that contain database connection passwords into your repository.
Upvotes: 1