In the realm of front-end development, the browser serves as a primary workspace for developers. They frequently engage in tasks such as refining interaction flows, determining transition durations, and validating API calls. Any distractions that pull them away from this environment can hinder productivity.
This article explores the experience of developing on Coursera’s front-end without relying on a heavy virtual machine, leading to insightful discoveries about the benefits of this approach.
The Approach Taken
To begin this process without the virtual machine, two key requirements emerged:
- A method to serve static assets (HTML, JavaScript, and CSS) to the browser.
- A mechanism to proxy API requests for essential data needed to build the client-side application, including class and user information.
Given the absence of a web server typically hosted by the virtual machine, a lightweight solution was necessary. The team opted for Express.js to serve compiled assets. Setting up Express was straightforward, enabling static assets to be hosted at localhost:9000/static
quickly.
Addressing API Requests
The second challenge involved efficiently resolving API requests to gather data for constructing the single-page application. This data encompassed course details and student information. To avoid burdening developers with data generation, existing data sources were evaluated for potential solutions.
Two distinct strategies were developed based on varying development needs:
- First Approach: For rapid UI visualization and frontend iteration, mock data was generated as part of the testing suite. This mock data simulated server responses. Utilizing Require.js allowed for easy rerouting of data requests to these mocks. Given that comprehensive testing is a priority, mapping data resources to mock data proved seamless and effective. This combination with the Express.js server provided a robust solution for running Coursera without a virtual machine.
- Second Approach: Recognizing that staging servers powered all necessary APIs, a proxy was established between the Express.js web server and these staging instances. This setup enabled local front-end development while leveraging more powerful backend servers. Consequently, developers could iterate on the front end swiftly while accessing persistent data for complete interaction flows.
Insights Gained
The process yielded several unexpected advantages that enhanced the development experience:
- Validation of Mock Data: The creation of extensive mock data is crucial for achieving thorough test coverage of client-side code. However, inaccuracies can occur during this process—some data may lack essential fields or contain errors. Building the entire application within the browser ensured that mock data was genuinely usable in test suites.
- Improved Battery Life: Developers often face challenges with laptop battery life, particularly when using virtual machines that can drain power quickly. By eliminating the virtual machine from the equation, developers experienced longer battery life, allowing them to work in their preferred environments without interruptions.
The Future of Front-end Development
For front-end developers, maintaining focus on their core responsibilities is essential. Coursera’s use of Express.js facilitates a more streamlined and efficient development process. Furthermore, this approach lowers barriers for those looking to contribute to front-end code—such as technical designers and marketers—who wish to engage with code without navigating complex virtual machine setups.
Running front-end applications independently from backends allows developers to concentrate on their work within its natural environment, optimizing efficiency and productivity.
Read more such articles from our Newsletter here.
Add comment