简体   繁体   中英

Javascript best practices with web sockets

I am going to make my website more interactive with websockets to update content without having to refresh. On server side, my Play! application is well structured, I have a controller per page. But in javascript, would you write a file for each page like

websocket_page1.js ... websocket_page2.js ...

Or something else ?

I will have stuff like a header with facebook like notification icons, some feeds with infinite scrolling, some action buttons.

More generally, is there any JS code writing convention like there is a structure for the Play! project ?

thanks, Julien

There is no preferred way to structure your Javascript in Play. This imposes some more work upon you, but also leaves you more flexible. If you need an opinionated approach to Javascript, there's a lot for you out there: from backbone.js to AngularJS . Some are easier to use, some are smaller, some provide a stronger structure. Just have a look through them.

You should also at least have a look at Ractive.js . Haven't used it so far, but it sounds awesome.

But, well, to come back to your question: you don't need some JS framework. Just do what you think fits your project. These frameworks might help you, but at the end of the day, it's up to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM