I开发者_C百科 have recently begun the practice of using <%# Ruby on Rails comments %> in my html.erb files, as these do not display in the source code that is then viewable by a user.
Is there a way of adding comments to .css files that keeps them private from the eyes of devilish onlookers?
As @Eimantas already said: it's not a good practice to send unminified version of JS/CSS files in production (you will get bad mark in YSlow for that).
There is a nice gem: http://github.com/thumblemonks/smurf
And it works like a charm: all you need is to mention it in your gem file (Rails 3)
gem "smurf"
and that's it! Well, that's it if you use :cache => ... in your stylesheet_link_tag:
stylesheet_link_tag "foo", "bar", :cache => "public.css"
It intercepts standard Rails behavior that saves concatenated files to disk and compress them just before.
And to mention the obvious - it will compress the file only in production mode as the :cache option works only if cacheing is enabled.
The same as for HTML — strip them before delivery to the client (either server side, or before uploading).
You may want to link a minification tool (e.g. YUI compressor) into your build/publication process.
You can use Sass to author your stylesheets, it has a //
comment syntax that is not emitted in the output CSS. (I recommend you use it via Compass, especially if you're using Rails).
Sass has a syntax variant called SCSS, which is fully CSS compatible if you don't love the indented structure of Sass.
精彩评论