Garbage Burrito

TinyMCE Ruby on Rails GZip Compressor

TinyMCE Ruby on Rails GZip Compressor
Ben Kittrell - 10 01, 2006 @ 10:28PM
Comments: 4

UPDATE:  I've refactored this into a Plugin.

I've been pretty happy with TinyMCE, especially after I discovered the Word Pasting plugin.  The one thing that has bothered me is how it loads JavaScript files for all the plugins and their languages.  Every time it loads I notice it chugging along.  Even if the pipe is fast it still takes time for each request.


They already have solved this problem, however it takes some serverside magic.  I did some searching and didn't find any solutions for this in Ruby.  After putting it off for awhile, I finally decided to try it myself.  

I used the PHP and JSP scripts as examples and pieced it together.  It aggregates all the plugin JavaScript files into one, gzips it if available, and caches the output.  I stole the gzip code from this project .

I have only tested this on my application, so I would appreciate it if some other people would try it out.  Once I get some feedback, I'll release it as a plugin.

To set it up, download this controller and put it into your controllers directory.  After that you need to add the following lines to your routes.rb.

map.connect '/javascripts/tiny_mce/tiny_mce_gzip.js', :controller => "tiny_mce_gzip" map.connect '/javascripts/tiny_mce/tiny_mce_gzip_load.js', :controller => "tiny_mce_gzip", :action => 'aggregate'

Then you just need to load the load the new JavaScript instead of the old tiny_mce.js.  

<%= javascript_include_tag("tiny_mce/tiny_mce_gzip") %>
 
This assumes that you have your tiny_mce installed in /javascripts/tiny_mce.  This is necessary to load the images and other js files.  

Have fun, and leave feedback here in the comments.

Comments: 4

Comments

1. Ben Wagaman - 10 13, 2006 @ 12:31PM

I noticed a little bug in the tiny_mce_controller.rb. If you don't have plugins, you get the usual nil error.

unless plugins.nil?
plugin_list = plugins.split(/,/)
for plugin in plugin_list
plugin_file = File.join(tinymce_dir, "plugins", plugin, "editor_plugin#{suffix}.js")
language_file = File.join(tinymce_dir, "plugins", plugin, "langs", "#{lang}.js")
content += File.read(plugin_file) + "\n"
content += File.read(language_file) + "\n" if File.exists?(language_file)
end
end

This was a quick bug fix, however after I set everything up, I'm not getting the TinyMCE box to load like the non gzipped. In the non gzipped setup, I'm calling tinyMCE.init. any differences?

<script type="text/javascript" >
tinyMCE.init({
mode:"textareas", editor_selector : "tiny_mce",
theme_advanced_toolbar_location : "top",
theme_advanced_buttons1 : "bold, italic, underline, strikethrough, separator, bullist, numlist, separator, charmap, undo, redo",
theme_advanced_buttons2 : "", theme_advanced_buttons3 : "",
theme_advanced_toolbar_align : "left"
});
</script>

2. thabenksta - 10 13, 2006 @ 05:01PM

I just posted a new version of this as a plugin. It's completely re-vamped, so try it out and let me know if you have the same problems.

http://garbageburrito.com/blog/entry/89

3. Anonymous - 11 28, 2007 @ 12:57AM

sss

4. patricia - 07 30, 2008 @ 07:01AM

SUPRI+ Artigos para Laboratório com mais de 10 anos de experiência no atendimento a comunidade cientifica a SUPRI+ foi criada com objetivo de estreitar ainda mais esse relacionamento oferecendo produtos de alta qualidade de fornecedores renomados

Post a Comment




powered by : Doodlekit Online Free Website Builder : developed by : Doodlebit™ Website Company