Because I just learned rails, I tried to create a small system to operate a public account,
After the deployment, I encountered a problem. The whole system was very slow to access on the Internet, but the access on the mobile phone was 10 seconds later,
Open the chrome debugging tool and find that the application-(xxxxdigestxxxxxx). js file contains more than 800 k
Open this file and you will find that there are uncompressed jquery comments and Code for the re-control ckeditor.
So the problem becomes
1. How to dewatermark jquery
2. Load other heavy controls, such as ckeditor js (500 k), as needed)
1 is actually a mistake made by myself, because I didn't bring the correct production parameters during pre-compilation.
Rake assets: precompile RAILS_ENV = production
Why didn't I write it like this at the beginning? Because I added this parameter at the beginning, but I found that the terminal was "stuck" when it was added, so ctrl + c stopped the execution.
Later, it was found that, instead of getting stuck, some JavaScript code with heavy controls was complicated, and node. js is still performing operations. For example, it takes about 3 minutes for ckeditor to execute precompile in my notebook.
We all know that application. js is referenced in layouts/application.html. erb, and application. js contains a sentence by default.
// = Require tree. The meaning of this sentence is to add all js files under the Directory
If we want to load js separately, we must first kill this sentence.
Then, you need to reserve a yield position for the header in layouts/application.html. erb to load your js Code on the specified page.
I added <% = yield: head %> after <% = csrf_meta_tags %>.
Then load the specific js on the specific page. Load the corresponding js on the specified page. For example, here
<% Content_for: head do %>
<% = Javascript_include_tag "ckeditor_load", "data-turbolinks-track" => true %>
<% End %>
Of course, you need to write the ckeditor_load.js file in app/assets/javascripts. Note that you need to add the precompile compilation range to config/application. rb.
Config. assets. precompile + = ['admin. js', 'ckeditor _ load. js', 'swfobject. js']
Finally, rake assets: precompile RAILS_ENV = production
In this way, js classification can be used for loading, JavaScript compression, and deletion of comments and other information. application. js starts from 800 KB and ends at around KB of the general page, which is more scientific.
References
Http://guides.rubyonrails.org/asset_pipeline.html
Http://chloerei.com/2013/03/10/rails-assets-pipeline-s-value/
Here is a little bit. After I posted a message on rei's blog, rei almost immediately replied. Later I thought the blogger's profile was very familiar and finally remembered it, this guy is ruby-china's first member (http://ruby-china.org/rei), suddenly scared.