Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse whitespace? #29

Closed
drewhamlett opened this issue Apr 3, 2014 · 6 comments
Closed

Collapse whitespace? #29

drewhamlett opened this issue Apr 3, 2014 · 6 comments

Comments

@drewhamlett
Copy link

Can you add a flag to collapse whitespace, I have a large project and I compiled the templates using the Grunt angular plugin just to see and it reduces file size significantly. It seems they are running an html minifier and it's collapsing the whitespace. Thanks!

@pitr
Copy link
Owner

pitr commented Apr 4, 2014

Interesting. Looks like the grunt plugin uses html-minifier. Would you be able to work on this?

@drewhamlett
Copy link
Author

Hi yea I'm working on this. Also what's the deal with all the '\n' the to_json method makes. We don't need that. I'm looking over the documentation and I'm assuming it uses the
JS_ESCAPE_MAP.

At least escape_javascript does.

http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html

@drewhamlett
Copy link
Author

Ok I did something like this.

Not sure if it's correct but it seems to be working. Not passing tests right now though.

https://github.com/drewhjava/angular-rails-templates

EDIT

Ok, I ran this on my application and it only dropped the total file size 30kb. Went from 850kb to 820(239kb gzip) Haha. Still think it's worth it though.

EDIT:
Ok the size savings maybe a lot bigger then this. It seems sprockets is still caching the templates that have not changed when I deploy to Heroku. Need to figure out how to change this.

Be careful when updating if you test this because it updates sprockets(cause it's not locked) and there is an issue with sprockets and SASS I ran into.

activeadmin/activeadmin#3005

@whitehat101
Copy link
Collaborator

I like the idea.

It's kind of a bummer that you're using an 0.0.7 release of a html compressor, seeing as this project is also in early development. I haven't looked around, and I don't know what, if anything, is better.

About \n, instead of re-implementing escaping. Why not use a standard tool:

data.to_json.chop! # I'd guess this would be most efficient
data.to_json.chomp!
data.to_json.rstrip!
data.to_json[0...-1]

I don't know if any these have performance consequences for long strings, but I definitely prefer using them over monkey-patching String.

@whitehat101
Copy link
Collaborator

@drewhjava I've been working on a lot of enhancements to this gem, one of which is support for HtmlCompressor, inspired by your work. I'd appreciate it if you could give it a spin.

https://github.com/whitehat101/angular-rails-templates

I did introduce some non-backwards compatible changes to the gem. I think I mentioned them all in my readme, but here is a quick version:

#Gemfile
gem 'htmlcompressor'
gem 'angular-rails-templates', github: 'whitehat101/angular-rails-templates'

# config/application.rb
config.angular_templates.htmlcompressor = {remove_intertag_spaces: true}

# config/environments/development.rb
# add this, restart the webserver, and any change you make to this string will rebuild all your assets
config.assets.version = '1.1'

# app/assets/javascripts/application.js
//= require angular-rails-templates # before you require templates

All assets now need to have .html in their name. .nghaml and .ngslim aren't supported.

index.html
foo.html.haml
bar.html.slim

@pitr
Copy link
Owner

pitr commented Apr 30, 2014

thanks both @whitehat101 and @drewhjava ! 0.1.0 has the HTML compressor.

@pitr pitr closed this as completed Apr 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants