In my middleman static site, my images, fonts and CSS are properly going through the asset pipeline, and getting their fingerprint suffix (img/logo-3e4a3149.png for example).
However, my mp4 files that reside in the assets/vid folder are just copied as is with the same name, which makes them stale (cache wise) when built and deployed.
How can additional asset types (mp4) be configured to be treated like images in this regard?
The file extension '.mp4' is not considered as asset files by default, i.e. are not listed in asset_extensions.
Adding the file extension to the list fixes the issue (as you already figured out yourself).
Options to do so:
config[:asset_extensions] += %w[.mp4]
# or
config.asset_extensions += %w[.mp4]
# or
activate :asset_hash do |asset_hash|
asset_hash.exts += %w[.mp4]
end
# or
# Passing `ext:` argument overrides list of file extensions!
activate :asset_hash, exts: %w[.css .png .jpg .jpeg .webp .svg .svgz .js .gif .ttf .otf .woff .woff2 .eot .ico .map .mp4]
Well, answering my own question, although I am not sure this is the approach intended by the developers.
Found the source code for the AssetHash extension, which provides some insight.
Found what seems to be an outdated configuration documentation that happens to mention the asset_hash setting (although the mentioned syntax does not work).
So after fiddling with it, I came up with this in my config.rb
activate :asset_hash # this was always there
config.asset_extensions << ".mp4"
It seems a little dirty, since all other settings in the middleman config are elegantly set using the set :something DSL, but at least it works.
I also noticed that this syntax works:
activate :asset_hash, exts: [".mp4"]
but it replaces the factory settings.
If someone finds a better option, please share.
Related
I'm using a shared 1and1 package for a Magento website and it seems I can't use the standard approach of compressing css and js files via htaccess. I came across this http://mrrena.blogspot.co.uk/2009/01/how-to-compress-php-and-other-text.html which gave an interesting approach which seems to work. However, I need to put a php.ini file in every directory that has css or js files that I want compressed. For something like Magento, this is quite a pain. Is there any way I can use a hierarchical approach such as with htaccess?
I discovered the .user.ini file which does precisely what I want. So now I have a single .user.ini file in my root folder and I've removed all of the php.ini files.
See here for some detail: http://php.net/manual/en/configuration.file.per-user.php (none of the online documentation I could find on .user.ini was particularly good).
I'm playing with Padrino, experimenting with a very minimal site at the moment with no DB and just a few HAML and SASS files under the app/ directory.
What I've noticed is that each time I render a page which links to a stylesheet that's defined in a .sass file, it compiles the stylesheet to .css and stores it under public/.
This is all very well, but I also have some static assets stored in public/, including images and some other hand-written .css files.
What this means is that my public/ directory becomes a mix of things I placed there and things compiled by Padrino. So, looking in there will show a bunch of .css files, some of which are compiled .sass files, and some of which are my actual primary static assets. This is confusing.
Is there a way I can stop Padrino (or Sinatra, or Rack, or whatever is doing it) from saving these compiled files during development, and keep my public/ clean?
Alternatively, can someone explain why what I'm asking for is a bad idea / by design / I should learn to love it instead? :-)
Thanks.
I don't know how to set the SASS settings for Padrino, I had a look and couldn't find anything helpful either. I would feel a bit nervous about running it this way too, it could easily get confusing and unhelpful, and what if the asset names clash?
What you could do is not add SASS in via Padrino, and then run it yourself either via the --watch switch or via something like Guard. That way you can also specify different subfolders within the public directory (images/css/js etc), which is what I do (although it does mean you need to remember to add the subfolder as part of the path when describing links). The app doesn't even need to know you're using SASS, and precompilation, when it's this simple, is surely better than the kind of compilation on demand that you've got at the moment (IMO).
You might try the Padrino mailing list for help with the settings.
Using the padrino-sprockets gems I also wanted to change the default /public/stylesheets directory to /assets/stylesheets where sprockets pick them up. I found that my padrino project genereated with the -c sass option had a /lib/sass_plugin.rb file with the following:
# Enables support for SASS template reloading for rack.
# Store SASS files by default within 'app/stylesheets/sass'
# See http://nex-3.com/posts/88-sass-supports-rack for more details.
module SassInitializer
def self.registered(app)
require 'sass/plugin/rack'
Sass::Plugin.options[:template_location] = File.join(Padrino.root, "app/stylesheets")
Sass::Plugin.options[:css_location] = File.join(Padrino.root, "public/stylesheets")
app.use Sass::Plugin::Rack
end
end
Editing the :css_location path and restarting Padrino did the trick!
I am using the activeadmin gem which proposes a little weird way of including additional assets to those automatically generated by the gem:
https://github.com/gregbell/active_admin/issues/492
My problem however is that though in config/application.rb I do set
config.assets.precompile += ['active_admin.css', 'active_admin.js', 'my.css', 'my.js']
my_file.css and my_file.js are not served in development mode, it's Routing error.
I have registered them with the activeadmin's own config.require_javascript and config.require_stylesheet, which seems to work, since generated html contains the respective script tags.
However the /assets/my.css and /assets/my.css are not responsive.
What could cause a problem, how do you think?
It turned out that the files I was trying to add were corrupted somehow since creating the new ones and copying the content inside made a trick.
I was including the .js and .css files of this plugin:
http://loopj.com/jquery-tokeninput/
which is fine not taking this issue into account.
Got a trouble when including some external javascript code (example can be jquery.treeview plugin with css and images included) - in vendor/assets (where this should go) it seems it doesnt work with images. Any experience or example of doing this?
I suspect it's because you need to correct /images/foo.jpg to the new scheme of /assets/foo.jpg
If not, please include logs and examples.
Along the lines of what Zach said, the solution I've used is to modify the js/css files to be erb templates, and used asset_path('treeview/foo.jpg') to replace '/treeview/foo.jpg', and move all plugin images to the app/assets/images/treeview folder.
This will make everything work swimmingly, but it is less than ideal in requiring hacking up plugins before they work with the new system.
Of course, you can also keep your CSS and JS files in /public/javascripts and just javascript_include_tag them as usual, but you'll lose the precompile/bundle/compress functionality the asset pipeline provides.
CKeditor's installation instructions tell me to just unzip the whole distribution file on my webserver's production directory. But it is full of files I definitely don't want there, like source code, examples, and even server-side code in PHP. I got rid of most of these files but there is one I'm not sure about: contents.css.
I can see this file uses a lot of styles I definitely don't want to see in my site. My question is:
Is contents.css required by CKeditor, or used by default? Do I even need this file on my production site?
I suppose it depends on what you're using in CKeditor, or what you plan to use later. Personally, I'd suggest renaming the file (something like) contents.css.old and creating a new contents.css file, copy across all the styles that you think you'll need and then destruct-test your implementation of CKeditor, to assess whether you've got all the styles that you need.
Add to, or remove from, that file to get your finished version and then use that one. I'd strongly advise keeping the original version around though, for future development purposes.
To your specific questions, though:
Is contents.css required by CKeditor, or used by default?
I believe so.
Do I even need this file on my production site?
Not so far as I know, its absence will likely cause things to look a little less-pretty, though, until you apply your own styles.
As suggested, above, though, I'd rename the original and then create your own stylesheet with the same name, it's rather easier than going through all the various js files looking for, and changing as appropriate, references to contents.css.