RequireJs: Using optimizer plugin to optimize custom directory structure - jquery-mobile

while creating a mobile web application using jquerymobile, jquery, requirejs, and backbone for routing, I was not able to optimize it by running the node.js command as instructed here:
http://requirejs.org/docs/optimization.html
So basically, I was trying to optimize my files to run faster because it loads very slow in mobile devices and as the application goes larger and more complex so as it becomes more slowly.
An example structure of my application can be found here:
https://github.com/3na/PulawJS .
That is the skeleton of my application, I will be glad to hear any comments and suggestions from you guys.
Thank you so much!

Related

Integrating a ruby program w/ GUI in a Rails application

This is somewhat hard for me to explain properly, sorry in advance if the question is unclear! I am fairly new to both Ruby and the Rails framework but I'm working on a Rails application in which I want to be able to run a self-made program with GUI.
The question is whether or not it is possible to just "have" the program running like it otherwise would in a page in the Rails application, and if so, how?
Yes, usually you can (if the app can be run in multiple instances). But whatever GUI stuff it does on the server won't be of much use to your webclients, it'll just needlessly strain your resources a little bit (or a lot--depending to what graphical operations it does). For web apps, you're better off using non-gui programs or better yet, libraries that you can use from inside ruby without needing to spawn separate processes.
Launching an app incurs a little bit of overhead, which however multiplies by the number of web clients you have.

Rails serverside handlebars performance

We are using server side handlebars in a backbone single page app rails project in a high traffic environment and we are finding that our rendering speed increased by 100%. We are using the sht_rails gem which appears to be well coded and simply handing off the rendering of the template to v8/execjs/rubyracer. After going live our GC increased a ton and we've tried various cacheing strategies to alleviate the issue but it's not going to work for us and we're about to bail on the idea of shared handlebars templates even though the benefits have been great from an seo/shared code standpoint.
Short of going with ruby ee, is there anything else we can do to fine tune/speed up this process? Or is it just the nature of the beast handing off strings to javascript serializing/deserializing and so on.
From our experiences it seems as though this server side rendering is not ready for production rendering. Anybody have any experience with this?
We ended up creating a node renderer service and handed the template rendering off to it instead of using the rails based ruby racer etc. Solved our problem for now. In the end it would have been nice to use node full stack to get better isomorphic support but we are a rails shop so this is where we are.

Phonegap and the universe of frameworks?

my concern is to find a well fitting framework for developing a cross mobile platform app via phonegap. I am using JQMobile for the User interface.
I want to build my Application well structured and modular. That means i want to keep it very well capsulated.
I know Backbone.js , Underscore.js , handlebar.js , Mustache.js.... and many more.
I am wondering what could be the best method of structuring my apps architecture?! Moreover: Are there big dependencies which result from using those frameworks?
Which framework is giving me the BEST expandability and performance Boosts?
Iam asking because i hope someone can give me a hint. That would save much time.
Greetings
Chris.
EDIT: USEFUL Information for readers.
My final decision is based on "http://coenraets.org/blog/phonegap-tutorial/". This is a Tutorial about developing a Phonegap Application. Christophe Coenraets is a Technical Evangelist from Adobe. He gives many advices how to develop Phonegap applications with good performance. The link directs you to a really nice Tutorial for Routing between Views, Css Scrolling with Phonegap and many architectural information more. There is also a 60 minute presentation about Performance / Architecture and more similiar stuff. I am using handlebars.js for HTML templating, fastclick.js to simulate "touch" for "click" for more performance and Twitter Bootstrap CSS Framework for the responsive Design.
Anyway thx for your answers!
First lets make something clear. Whatever you use, you will not gain performance boost. Even worse, there's a good chance your performances will be lower.
But what you will get is usability and readability + more functional code than it is the case with pure jQuery + jQuery Mobile.
The most commonly used combination is jQuery Mobile + Backbone + Require.js. From my experience, it is also the best one. Unfortunately, in the end, I think you will be disappointed. While this is an excellent combination, jQuery Mobile applications are usually slugish on Phonegap. So think about it.
I have several other articles discussing similar topic so take a look:
Switching from Jquery Mobile to AppFramework
Which mobile development open source Framework should I use?

Clarifications about Rails and Node.js

Up to now I've always used PHP with or without a framework but a month ago I decided to start something new: Ruby and Rails, I found them quite easy and similar to PHP and some PHP frameworks in how they works but using a simpler syntax and many other advantages.
Some days ago I started reading about Node.js, Node.js vs Rails, "why node.js is better"...
I'm a bit confused but my objective is to learn something modern that will not become obsolete in a few months so:
What are the main differences between Rails/Ruby and Node.js and a framework based on it like Express.js (except that one is written in JS and the other in Ruby)?
What are the main advantages/disadvantages of using Node.js and framework based on it instead of a Ruby based solution like Rails?
Thanks!
There aren't enough differences between Node.js and Rails for it to practically matter.
A lot of what Node.js can do can be pulled off in Rails with things like EventMachine and Pusher. So unless you are really familiar with Rails' limitations, and know you'll be pushing the boundaries, you'd be hard pressed to make something a seasoned Rails developer couldn't do.
Having built apps in Node and Express I can say that they alone aren't enough to make a sexy application. They can seem just as old and stale if you don't have an outstanding frontend UI to facilitate the backend possibilities. Instead of comparing backend servers, I think the real future of doing amazing things is in front-end JavaScript frameworks like Backbone.js that use Express/Rails/Node.js on the backend.
I have chosen to go in the direction of Backbone.js with Rails as my backend API server. Because it's so easy to rapidly create a very nice RESTful backend server in Rails. Rails also makes working with CoffeeScript and precompiling/organizing Backbone code a breeze. There are already decent Backbone.js gems out there for Rails.
The Rails core is also able to acknowledge and embrace the fact that frontend JS MVCs are logically a good next step, and they have been working to strengthen the bond between the two. For those same reasons they have also worked to make Rails an even better API server so that it can work with frontend JS easier. Node.js and Express aren't putting as much effort to coordinate with frontend JavaScript MVCs as the Rails community is.
Being good with a JavaScript frontend MVC and Rails as a backend makes you also great for both worlds in terms of getting a job. You will easily be able to hop onto a Node.js project and add value to that team with your superior frontend experience, and you can also roll with the punches on a Ruby on Rails team and add value to them as well.
As official Node.js website explains it:
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
On the other hand Ruby on Rails official website says:
Ruby on Rails is an open-source web framework that's optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favoring convention over configuration.
Given this I guess that it is more appropriate to compare Ruby and Node.js, but even this is not quite right given that Ruby is programming language and Node.js is NOT. You could probably compare JavaScript with Ruby but I guess that is not what you meant to ask with this question :)
So, for me, key point in understanding what Node.js truly tries to accomplish is well described on Node.js about page. Key Node.js idea (for me) is described in this sentences:
Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted. Node takes the event model a bit further—it presents the event loop as a language construct instead of as a library. In other systems there is always a blocking call to start the event-loop. Typically one defines behavior through callbacks at the beginning of a script and at the end starts a server through a blocking call like EventMachine::run(). In Node there is no such start-the-event-loop call. Node simply enters the event loop after executing the input script. Node exits the event loop when there are no more callbacks to perform. This behavior is like browser javascript—the event loop is hidden from the user.
What this should enable you, is that you should be able to easily write highly concurrent programs without even thinking about concurrency using JavaScript syntax and callback functions as basic concurrent runnable units.
Your fear that either Rails or Node.js will be gone in a week is unfounded. Rails has a large community and will be around for a very long time even though currently (early 2012) it's getting a bit of hate thrown its way. Node.js is just getting started and has so much attention I don't think it will have any problems getting to the Rails level some day.
That said I've been evaluating Node.js and Rails as options for a project and the reasons I choose Node.js over Rails are:
"The Rails Way" - In my (admittedly limited) experience with Rails it really seems like you either do it the Rails way or you are going to be in for a world of pain. A big part of the Rails way is to use the ActiveRecord model. The advantage of this is that there are a lot of gems that work with your code happily because they know you'll be using ActiveRecord. The disadvantage is you are mixing your data access & model. I am not a fan of this idea so the Rails way for me still seems a bit.. off.
JavaScript is a key part of client side web development and the idea of using it on the client and server is interesting. I'm not super strong at JavaScript and I can't imagine a better way to get better then to have to use it everywhere.
My project has real time communication needs which while I'm sure can be done in Rails there seems to be quite a bit of positive mention on Nodes ability to handle this with socket.io being the front runner option.
At the end of the day no matter which you choose you will have a great time & learn a ton of new stuff that will change how you write code. If you're not on a big time crunch I'd recommend building a small project management tool in both and see which you prefer.
Either way.. Good Luck!
2 things - performance & productivity.
Performance (more details here)
(source: jslang.info)
Productivity (how fast you can build that app)
Ruby on Rails is specialized and highly productive tool for creating so called Web 1.0 and Web 2.0 applications (99% of internet sites are such apps). In my subjective judgement and experience in this area Rails about 2-4 times more productive than node.js or express.js.
For Web 3.0 apps (realtime things, client-side MVC, etc.) this isn't true, RoR doesn't keep its advantage there.
So choice depends on use case and priorities.
I know a lot more about Node.js than I do about Ruby. That being said, Ruby is much more widely adopted. It is currently a very hot skill to have in the work place. Some may argue with me on this but I think that Node.js is still "under development" and will be for a little bit longer. It has a lot of promise but just hasn't been adopted by many companies and projects yet.

Can a rails app be compiled to run as standalone applications?

One of the nice things about Wt, the C++ framework for build websites, and Microsoft C#/.Net, is that the focus is on creating fully compiled applications (including built in web server) that run from binaries. This can give a real performance and scaling boost. I have seen Python compiled to machine code for HPC; is this possible for Rails apps?
Not exactly. The closest thing I know of would be to use jRuby to install your app as part of a Java application server.
As #heyrolled said, you can do it if you use jRuby, whereby your app is compiled into a JAR file that is loaded and ran by Tomcat.
However, I'd like to posit that this is premature optimization. Ruby and Rails are plenty fast for what you'd need and you'll more likely be experiencing bottlenecks on the database before the speed of execution by Ruby comes into question. Only when you have indexed the hell out of your database, cached the working set in memcached or redis, deferred to the background all the things that don't need UI interaction and are still running into performance problems do you need to consider language execution speed.
Whew, that was a long-ass sentence.

Resources