Search code examples
phpjqueryjsonjquery-mobilebackbone.js

Backbone.js vs PHP, jQuery Mobile website


I recently discovered Backbone.js and decided to learn it to build a single page mobile website at work. This website relies mostly on data from a remote JSON API (e.g. http://domain.com/players/username = {name: 'username', ...}).

I figure I can build a single page mobile site using jQuery Mobile and PHP with a well-structured MVC directory and use jQuery's .load() to pull PHP/html files dynamically. Would there be any benefit of using Backbone.js over PHP with a custom MVC structure mixed with JavaScript?

I started using Backbone.js and apparently now I need to use CORS because the API runs off a different domain and it's just starting to get complicated.

What's your opinion? I assume with PHP I might have both .php and .js constrollers and views so I don't know if that's bad practice.


Solution

  • If the server running the API doesn't have CORS enabled, then you will have to have some sort of backend to handle the requests for you. Depending on the complexity, you will not need to have both PHP and JS views/controllers/models. My suggestion is to have PHP controllers that relay your requests to the server and route the response back to the client. The PHP code would be acting as a sort of middle-man between your JS and the API you are using.