split application.css to overcome IE9 rule limit - ruby-on-rails

I am using css_splitter gem to split application.css to overcome 4095 rule limit in IE9.
app/assets/stylesheets/application_split2.css.split2
/*= include "application.css" */
config/environments/production.rb
config.assets.precompile += %w(application_split2.css)
app/views/layouts/application.html.haml
= split_stylesheet_link_tag 'application', :media => "all"
asset:precompile task succeeds and when i try to load the page, both application.css and application_split2.css files have the same content and the page is missing some of the styles. Am i missing something?
or Is there any other way of fixing the IE rule limit problem?

Related

Search robots can't index because of assets present rails heroku

On these websites https://staging.blockbutler.io and https://blockbutler.io (RoR on heroku both)
Google and Yandex search bots can't index with reason: 'robots.txt blocks'
but robots.txt is fine. And if you will remove
javascript_include_tag and stylesheet_link_tag it perfectly indexed the page. I spent 3 days of trying different tests - nothing helps:
if there are only javascript_include_tag with empty
application.js or only stylesheet_link_tag with empty
application.scss - no indexing
add gem 'rails_12factor' - no
indexing
rake assets:precompile RAILS_ENV=production and push static files from public/assets to server - no indexing
put assets in footer - no indexing
wrap assets in <noindex> and rel: "nofollow" - no indexing
I really don't know what da magic is going on and be really happy for any ideas
Logs when run google search console live test:
production.rb:
config.assets.js_compressor = :uglifier
config.assets.enabled = true
config.assets.version = '1.0'
config.assets.compile = true
robots.txt:
User-agent: *
Allow: /
User-agent: Yandex
Allow: /
User-agent: Google
Allow: /
Sitemap: https://blockbutler.io/sitemap.xml
p.s. sorry for bad english - will appreciate editing my language (:
Some freaking magic over here.
Change <%= javascript_include_tag 'application', rel: "nofollow" %> to <script src="/assets/application.js" rel="nofollow"></script>
And now google indexer works just fine. GooGLe InDExER DoesN'T LiKE BIg fiLe NamES. Will think about how to prevent cache assets file.
p.s. ok. Now every time Im updating assets - Im changing assets name, like applicationv0.js and etc. Still have no idea, why google wasn't ok with default application-hash.js filename

Missing assets on production mode - passenger on nginx

When i move to production many assets are missing. There is no background image but there are styles for background from css. Many JS doesn't load ..
I put in config production.rb :
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
In application.rb :
config.assets.precompile += %w( ie.css )
config.assets.paths << "#{Rails.root}/app/assets/fonts"
but fonts doesnt load. I see in public/assets all fonts but there isnt any on my site.
Can someone write answer - how config application to work on production ? Why i have xxx.jpg from css file but havent got yyy.jpg from that same css file..
CSS for background:
body{
line-height: 1;
background: #fff url('wallpaper.jpg') top left;
IMAGES location - assets/images
FONTS location - assets/fonts
Sometimes in chrome console i see :
GET ..../assets/wallpaper.jpg 404 (Not Found) xxxxxx/:11
GET...../assets/main_page.png 404 (Not Found) xxxxxx/:30
GET ...../assets/fonts/Lato-Bol.ttf 404 (Not Found)
and sometimes not, but always there is no fonts and many assets.
My application css:
*= require_self
*= require chosen
*= require fancybox
*= require page
*= require_tree .
*/
Try using image-url instead of url.
background: #fff image-url('wallpaper.jpg') top left;
From the Asset Pipeline documentation:
When using the asset pipeline, paths to assets must be re-written and
sass-rails provides -url and -path helpers (hyphenated in Sass,
underscored in Ruby) for the following asset classes: image, font,
video, audio, JavaScript and stylesheet.

Rails css isn't pre-compiled

I'm trying to use the gem 'gem 'rails_admin_nestable' to sort an ancestry enabled table. It works fine in development, but I get the following error in production:
ActionView::Template::Error (rails_admin/rails_admin_nestable.css isn't precompiled):
5: = nested_tree_nodes #tree_nodes
6:
7:
8: = stylesheet_link_tag 'rails_admin/rails_admin_nestable'
9: = javascript_include_tag 'rails_admin/jquery.nestable'
10: = javascript_include_tag 'rails_admin/rails_admin_nestable'
I have this line in my application.css
*= require rails_admin/rails_admin_nestable
Here is a pic:
I didn't think that I needed to copy the stylesheet into app/assets/stylesheets because I assumed the gem would load it.
But, I went ahead and put it there and I still get the same error.
Thanks !!
PS - I'm using RubyMine to edit my app. At the bottom of the directory list, it has "External Libraries". I thought I'd see the above stylesheet somewhere in this list - but, I don't see it.

Action view::template::error (Unexpected token: operator (<))

im getting a problem with my deploy at heroku!
I just created an app Test with cedar stack, push my app and I have this problem (log)
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m ActionView::Template::Error (Unexpected token: operator (<)
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m (in /app/app/assets/javascripts/application.js)):
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 3: <head>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 4: <title>Test</title>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 5: <%= stylesheet_link_tag "application" %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 6: <%= javascript_include_tag "application" %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 7: <%= csrf_meta_tags %>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 8: </head>
←[32m2012-03-24T15:10:56+00:00 app[web.1]:←[0m 9: <body>
Any Idea??
Update:
My application.js file
// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
I ran into this error and it took a while to figure out which file referenced in the manifest was the culprit. Once I figured out which file was causing the error, searching for '>' pulled up several lines but I got lucky and quickly zeroed in a map function which used the => operator:
.map(x => x.id);
Once I changed that to an anonymous function:
.map(function(x) { return x.id; });
the error went away.
I've just run into this problem, and the trick was that there was a remaining line of a conflict between the server and my localhost. In my localhost everything seamed fine, but i think that's because of some cache, or something. Anyway, i opened the application.js and remove the lines with the << HEAD...
I let it here for register of the problem and a possible solution
NOTE: it's been almost 7 years since the OP asked this question. The issue I experienced is likely a newer problem (with the same error log output as OP). The below answer likely doesn't apply to the issue the OP experienced, but could be helpful to new visitors looking for a solution.
My Rails version: 5.1.2
Found the problem
It was an issue with how Production handles my assets.precompile (in config/initializers/assets.rb)
After trial-and-error to find the culprit (a new JS file I created a week ago), I noticed the error vanished after commenting out the line that includes the file in config/initializers/assets.rb.
# Commented out until precompile fix found
# Rails.application.config.assets.precompile += %w( break_the_project.js )
THE FIX
Since this only happened in Production for me, I updated config/environments/production.rb, replacing the line:
config.assets.js_compressor = :uglifier
to:
config.assets.js_compressor = Uglifier.new(harmony: true)
After restarting the Rails server, my World was peaceful once again.
Source

Rails Asset Caching Breaks First few page loads

We're using Rails asset caching for JS and CSS like this:
<%= stylesheet_link_tag 'reset','global','admins','autocomplete', 'date_input', 'tablesorter', 'partners', 'jqmodal', :media => 'screen', :cache => set_asset_cache(:admins) %>
<%= javascript_include_tag :defaults, 'autocomplete', 'searchbox', 'jqmodal', :cache => set_asset_cache(:admins) %>
In our deploy we call rake tmp:assets:clear each time. The problem is that the first few page loads after a deploy come up with no css or js on the page. I guess until the cached all.js and all.css have been regenerated.
We deploy many times per day and this is scary for any users who happen to come across a busted page.
Have people found any way to make this smoother so the new cached assets are guaranteed to be there on the first new page load?
The AssetHat gem addresses this exact problem. Instead of concatenating assets the first time a page is loaded (which increases that page's load time), it concatenates assets on deploy instead. As a bonus, the gem also minifies your CSS and JS, which saves precious bytes.
After setup, usage is pretty simple:
Use include_css :bundle => 'admins' and include_js :bundle => 'admins' in your layout. (The bundle contents are set in a config file to keep your layout lightweight.)
Add rake asset_hat:minify to your deploy script. My company has been using it in production with Capistrano for about a year now.
There's more info in the readme and docs, and I'd be happy to hear any questions/ideas!
You could try warming the cache during deployment using wget, as an example (shamelessly reposted):
wget -r -nd --delete-after http://whatever.com/~popular/page/
However, this would have to be executed after you switch your symlink to your new deployment. A possibly more elegant solution might be to call the asset caching methods manually in your deploy, though I'm not sure how feasible that is. Here's where the caching is performed in Rails:
# File vendor/rails/actionpack/lib/action_view/helpers/asset_tag_helper.rb, line 273
273: def javascript_include_tag(*sources)
274: options = sources.extract_options!.stringify_keys
275: concat = options.delete("concat")
276: cache = concat || options.delete("cache")
277: recursive = options.delete("recursive")
278:
279: if concat || (ActionController::Base.perform_caching && cache)
280: joined_javascript_name = (cache == true ? "all" : cache) + ".js"
281: joined_javascript_path = File.join(joined_javascript_name[/^#{File::SEPARATOR}/] ? ASSETS_DIR : JAVASCRIPTS_DIR, joined_javascript_name)
282:
283: unless ActionController::Base.perform_caching && File.exists?(joined_javascript_path)
284: write_asset_file_contents(joined_javascript_path, compute_javascript_paths(sources, recursive))
285: end
286: javascript_src_tag(joined_javascript_name, options)
287: else
288: expand_javascript_sources(sources, recursive).collect { |source| javascript_src_tag(source, options) }.join("\n")
289: end
290: end
You might be able to modify the caching code and run it manually on deploy.

Resources