0

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.

4
  • Add a check of RAILS_ENV == production which reads from the min files? Commented Jul 2, 2012 at 22:02
  • @Isotope He didn't mention Rails! Anyway I think you are right, none of those are tasks for Git, even tough it could be done with a great effort! Commented Jul 2, 2012 at 22:12
  • Excuse me, sorry about that. I thought I had the tag filter on. Plan B: use capistrano for deployment and tell it to switch out the requires on deploy? :D Commented Jul 2, 2012 at 22:16
  • Thank you both, sorry I should've made it clear that I'm referring to HTML5 apps. I think I have incorrectly presumed that Capistrano was for Rails only. Commented Jul 2, 2012 at 22:30

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, please could you provide an example of what you would have in a sample config file?
Apologies for the questions but what kind of config file is this? Apache? Good point about not committing database connection details by the way.
It's a config file in a format that I'm used to using via the perl module Config::General
Ok thank you, I primarily work on HTML5 apps so I'd rather not introduce Perl into the equation though.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.