25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Single-page applications<br />

Most websites are broken up into pages in order to make the information they<br />

contain easier to consume. Traditionally this is done with a server/client model,<br />

where each page must be loaded from the server with a different URL. To<br />

navigate to a new page, the browser must send a request to the URL of that page.<br />

The server will send the data back <strong>and</strong> the browser can unload the existing page<br />

<strong>and</strong> load the new one. For the average internet connection, this process will<br />

likely take a few seconds, during which the user must wait for the new page to<br />

load.<br />

By using a powerful frontend framework <strong>and</strong> an AJAX utility, a different model<br />

is possible: the browser can load an initial web page, but navigating to new<br />

pages will not require the browser to unload the page <strong>and</strong> load a new one.<br />

Instead, any data required for new pages can be loaded asynchronously with<br />

AJAX. From a user's perspective, such a website would appear to have pages<br />

just like any other, but from a technical perspective, this site really only has one<br />

page. Hence the name, Single-Page Application (SPA).<br />

The advantage of the Single-Page Application architecture is that it can create a<br />

more seamless experience for the user. Data for new pages must still be<br />

retrieved, <strong>and</strong> will therefore create some small disruption to the user's flow, but<br />

this disruption is minimized since the data retrieval can be done asynchronously<br />

<strong>and</strong> JavaScript can continue to run. Also, since SPA pages usually require less<br />

data due to the reuse of some page elements, page loading is quicker.<br />

The disadvantage of the SPA architecture is that it makes the client app bulkier<br />

due to the added functionality, so gains from speeding up page changes may be<br />

negated by the fact that the user must download a large app on the first page<br />

load. Also, h<strong>and</strong>ling routes adds complexity to the app as multiple states must be<br />

managed, URLs must be h<strong>and</strong>led, <strong>and</strong> a lot of default browser functionality must<br />

be recreated in the app.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!