Moving To Javascript Development

in Javascript

Over the last couple of years there's been a growing trend in web development, this is the moving away from traditional back-end development and more to front-end development using Javascript.

This has been helped by the increase of nodeJS in web applications allowing Javascript to slowly but surely take over the world.

For many years PHP has been the leading web language, whether you like it or not it's market share has always won out for many years. This has now been overtaken by Javascript and it's easy to see why.

It moves away from the traditional web development approach of having to hire

  • Frontend developer - Traditionally just converted PSDs to HTML and CSS
  • Backend developer - PHP, Ruby, ASP.net who will code up the linking of the front-end to server
  • Devops developers - To handle the server construction
  • Mobile developers - Creating the ios and android apps
  • Desktop application developers

In the current day Javascript developers can handle all these areas of development. Frontend development is no longer just processing HTML and CSS you can build the entire product in Javascript. It's used to handle events on your frontend, Javascript then becomes the API to process the data storing in JSON, NodeJS is now your web server and using something like React Native you can create native mobile apps in Javascript.

Now companies no longer have to hire 4 specialist developer positions as these can all be done by a Javascript developer. This shift from hiring 4 specialist developers to hiring 4 Javascript developers will not only massively improve the process of development but the speed of development too. No longer does each stage have to wait for a dependency from another developer in a different section of the app, each developer can cover all areas of the application.

Below you can see the progression of JavaScript developer jobs. javascript-developer

When you compare that to the progression of the PHP developer jobs. php-developer

You can see if you're a Javascript developer you have some good years coming to you.

I've been a PHP developer for many years and I can see the direction that the web is heading to be more Javascript development and away from traditional development processes.

So it's time to change my development practises and learn more about Javascript development. I've been using Javascript for over 15 years but have never used Javascript to build an entire website. So the question I ask when learning a new language/process is where do I start? How to I go about learning frontend development with Javascript?

Where To Start With Javascript Development?

This has been the hardest question to answer with Javascript development as there are so many good frameworks out there at the moment, which one do you choose?

This just names a few of the frameworks.

Which one do you choose?

I asked this question on Twitter, but I didn't want to just say what framework should I learn? I did some research and saw that the 2 main frameworks used are Angular or React. As these were the biggest with the largest communities and with the highest job prospects I wanted to go with one of these. Therefore I asked the question which framework should I learn Angular or React?

The replies I had to this tweet were very surprising, there was a mix between Angular and React with React coming slightly ahead. The surprising part was with the amount of people suggesting vue.js over any over framework.

Looking into Vue.js on github you can see how quickly this is gaining popularity and should be taken seriously. But looking at employability the main contenders are between Angular and React.

While searching for a comparison of the two frameworks I found this project TodoMvc which is a Github repository that builds a simple To-do application using multiple different frameworks, this is a great way of comparing the different frameworks while they're performing the same actions.

TodoMvc

To see the code of the React Todo project you can view it here.

React Todo App

To see the code of Angular2 Todo project you can view it here.

Angular2 Todo App

To see the code of Vue.js Todo project you can view it here.

VueJs

Angular Vs React

1-mrpl_snurgjchb6eoanksa

As I'm not in a good position to compare these two frameworks so I've linked to the resources I used to make my decision.

The main difference between these two is that Angular is a Javascript framework and React is a Javascript library, which means it's the difference between buying a complete computer compared with buying the parts to build your computer.

Going on what I've read in the above articles about both Angular 2 and React, I've decided React is a better framework for me to learn. But then I was thinking about what people were saying on Twitter and how most people replied with VueJs, so I had to consider this in my choice.

VueJs

Vue (pronounced /vjuː/, like view) is a progressive framework for building user interfaces. Unlike other monolithic frameworks, Vue is designed from the ground up to be incrementally adoptable. The core library is focused on the view layer only, and is very easy to pick up and integrate with other libraries or existing projects. On the other hand, Vue is also perfectly capable of powering sophisticated Single-Page Applications when used in combination with modern tooling and supporting libraries.

If you are an experienced frontend developer and want to know how Vue compares to other libraries/frameworks, check out the Comparison with Other Frameworks.

Compared with the other frameworks Vue looks very powerful, easy to learn and fast.

When using a language the size of the community is very important, the more people that use it the easier it is to find support. Looking at the top Javascript frameworks on Github you can see that Vue is gaining a lot of popularity.

javascript-frameworks

As you can see from the image above Vue is 3rd most popular framework on Github behind Angular and React. When you consider the fact that Vue hasn't been around as long as the other two you can see it's going to catch up quickly.

Another point you need to look into when picking a language/framework is the progression of the product, if it hasn't been updated for a couple years then you don't really want to be using it. Vue have recently released version 2 of the framework increasing the speed of the framework.

Vue 2.0 Changes

Laravel

From Laravel 5.3 Vue is being included in the build and will be the focus to creating the front-end of your application. This is just the start of using Vue but this could mean the move away from Blade to be replaced with Vue.

This makes laravel a very good choice to use for the API of your app and use Vue to consume the API.

With Laravel making this move to include it in the build you will see a lot more people taking up Vue for their applications as opposed to React or Angular. For these reasons I've chosen to start learning Vue as I believe in the next coming of years it will gain more and more popularity in front-end development.

What's your opinions on the different frameworks?

VueJS With WordPress

If you've been following my blog recently you would be aware that most of the posts lately have been about creating a WordPress theme using VueJS and the WordPress REST API.

I've had a lot of great feedback from people really interested in learn more about using VueJS with WordPress. One of the most interesting questions I've had is Why? Why spend the extra effort in building your theme using VueJS when you could just use the standard WordPress theme.

I thought this was a very interesting question as most articles around development go over the how you do something but not many people discuss the why you would do it this way over the previous way.

Some of my main points to learn how to build a WordPress theme with VueJS are:

  • Performance
  • Data use
  • Security
  • Technology

Performance

The biggest benefit you get to when building your WordPress using JavaScript is performance.

If you think about what your server needs to do when a page is requested, it not only has to fetch the data to be shown on the page but also fetches via HTTP images, CSS and JavaScript files. It also has to do this while your visitors are navigating around your site, on each page load you need new requests to the server to find the images, CSS and JavaScript files.

Using a JavaScript framework, when the user navigates to the site it first needs to fetch the page information via HTTP, any requests after this will just need to replace the data on the page and then any page specific assets. The page data in this instance will generally be returning JSON, therefore, the requests are very fast.

This type of development will not only reduce the server load and power needed by the server but will speed up your app to your end user.

The data HTTP request only needs to return the JSON data which can be very light, compared to fetching a whole new page.

Think More About The Data

This type of development (I find anyway) helps improve the efficiently of your application, it makes you think more about the data you're fetching and if you actually need to get this data or not.

For example on a WordPress Single.php page, behind the scenes, WordPress could be performing multiple queries without you really knowing about it. It will perform a query to fetch the post data, a query to fetch the custom metadata, a query to fetch the category data, a query to fetch your author data and queries to get the comments. Plus there may be multiple queries from any third party plugins you use. Developing with an API-first approach makes you think more about what data you need and the best way of getting your data, for example, we could get all the data mentioned above using a single query with database joins.

Now I can make one HTTP request, one DB query and have all the data I need to run on the page. Reducing the load on the server and improving the experience to the end user.

Security

Another big benefit is security to your application. I love WordPress it's my favourite CMS by far, it's also the most popular CMS in the world, it also has an open source code base. This open source code base is the main reason why it's the most popular CMS in the world, but it's also the reason why it's the most attractive website for hackers.

Hackers know 25% of the internet is ran on WordPress, so if they can work out a security hole in WordPress they can attack 25% of the internet. Plus they have the added benefit of being able to view the code they want to attempt to attack, they can also view the changelogs of this code.

This means if the WordPress team go on a fix a security flaw in version 4.8 the hackers know they can exploit this security flaw in all versions of 4.7 and lower, that's a lot of the world's websites they can attempt to attack.

The way people get around this to try to hide the fact the website is using WordPress or remove the version number from the head tag.

Using a JavaScript framework you mask the fact you're using WordPress behind a REST API. You can add OAUTH security to your API and hide your admin area behind a firewall or IP blocking and you've improved your security. You've also stopped the classic brute force attacks on your login page, this is where hackers write bots to visit www.yourwebsite.com/wp-login.php and try a number of combinations on your login page.

With a JavaScript application, you no longer have a wp-login.php page. Login authentication is dealt with using tokens either JWT or OAuth allowing you to authenticate every single request to the server. The benefit of OAuth token-based applications is if a user account is compromised you can simply disable the token and that user will not have access to the make any request, even to just get content.

Technology

When you build with a API driven approach you can have more flexiblity on the technologies you use. For example if I build a site using WordPress as the back end and a VueJS front-end if I want to I could switch out WordPress with a new CMS or custom built API and I won't have to change the front-end at all.

This gives the project more freedom to continue to progress with the new techonologies being released to improve the flow of the website and speed up performance.

Subscribe To Newsletter

Get weekly updates to your email