OneChillDude
OneChillDude

Reputation: 8006

Rails, HAML, and Angular.JS, any way to precompile HAML?

I'm starting to add angular to my rails project, which is powered by HAML. HAML is nice because it saves a ton of time on coding and makes my code way more readable, however, HAML is slow.

Is there any way I could write HAML, precompile and/or cache it, and then allow Nginx to serve the static HTML without ever hitting the unicorn server. The goal is to avoid having to invoke ruby to render the HAML each time.

I thought about writing html directly in public/, but that seems lazy. Bonus question: Are there better options than HAML with angular? Am I causing myself unnecessary stress for the sake of familiarity?

Upvotes: 0

Views: 151

Answers (1)

rovermicrover
rovermicrover

Reputation: 1453

Set the http header in the controller for each of the views that will be for all purposes "static" from the view point of server side rendering via

expires_in 1.year, :public => true

Then put amazon cloud front in front of the actually web application, and use Cloudfront to distribute all views that are static besides content handled by Angular and Ajax requests.

One of the projects I work on we allow people to post widgets on there site that show the status of their account, we do this by distributing all widgets through Cloudfront with a

expires in 10.minutes, :public => true

Basically rate limiting each client to only hit the actually server once every 10 minutes. The same theory would apply here. You would also have to change the url based on your version number, in order to invalidate the Cloudfront cache on updates.

Sense Cloudfront is cheap comparatively to server side rendering, or disk reads this should result in a gain in speed and your bottom line.

Upvotes: 1

Related Questions