Skip to main content

browserify – write client-side javascript server-side

thechangelog:

Unifying your front-end and back-end codebases can be a harrowing experience. Regardless of your web technology stack of choice, you’ve probably created some server-side component which generated some front-end JavaScript for you at some point. I’ve created and used many tools that do such code generation, and I’ve hated all of them. This is why I’m soo excited to see node-browserify by prolific Node.js module author,James Halliday.

browserify is a node.js library which helps you share your back-end code to the front-end by enabling such features as:

  • a client-side require() method
  • being able to load npm packages
  • a middleware system for code generation:
    • minify
    • uglify
    • ES5 compatibility
    • fileify ( wrap static files or directories in JavaScript methods )
  • a CLI tool for creating stand-alone bundles
  • full integration with node’s httpServer and Express
  • browser-versions of certain core node modules such as path, events, and vm

Browserify does a great job of simplifying the process of sharing code between the browser and server by building on top of existing infrastructure and providing some great new features that play very nice with node.js

I needed to build a library that would operate dual-sided ( front-end and back-end ), and I choose to build it server-side first and then use the browserify CLI tool to port it to the client ( and work as a standalone with no server dependencies ). The entire process worked out much better then expected and I’d recommend trying it out for your next JavaScript project.

If you’d like to see an example of node-browserify in production, you can check out Browserling, Mr. Halliday’s very own company which allows you to test websites cross-browser, in your own browser! I can only imagine what crazy libraries SubStack will think up next.

Related Posts:

SplMaxHeap aka SelfSort-“array”

class MyListHeap extends SplMaxHeap {
  public function compare( $value1, $value2 ) {
    return ( $value1['created_at'] - $value2['created_at'] );
  }
}

$list = new MyListHeap;

$list->insert(array('user_id' => 1, 'created_at' => time()-2000));
$list->insert(array('user_id' => 2, 'created_at' => time()-1000));
$list->insert(array('user_id' => 3, 'created_at' => time()-5000));

foreach($list as $l) {
  echo "{$l['user_id']}:{$l['created_at']}\n";
}

And the output will be:

2:1309908000
1:1309907000
3:1309904000

And the output will be:

2:1309908000
1:1309907000
3:1309904000

Read more: http://hu2.php.net/splmaxheap

Related Posts:

  • No Related Posts

How to extend the ArrayObject and create a custom array

to my friend with lots of love

class MyArray extends ArrayObject {
  public function __construct($array = array()){ 
    parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
  }

  public function get_property_string($sep = ':') {
    return implode($sep, $this->getArrayCopy());
  }

  public function __ToString() {
    return 'Array';
  }

  /* some custom method */
}

$rights = new MyArray;
$rights->append('LOGIN');
$rights->append('BETA_ACCESS');
$rights->append('WRITE_COMMENT');

var_dump($rights->get_property_string());

And the output will be:

string(31) "LOGIN:BETA_ACCESS:WRITE_COMMENT

Read more: http://php.net/manual/en/class.arrayobject.php

Related Posts:

  • No Related Posts