Fast means fast. Web application nowadays can offer much more in very less effort. But we also need fast delivery of the responses for the incoming request. So, here is the list I maintain for my application to be faster.
Never use resources inside a loop
Resources are not supposed to be used inside loops. Resources means mechanism that has capability to communicate with other application. For example, database connection. It is highly recommended that never perform any SQL queries inside a loop.
Same goes for sockets, file operations etc.
If you result is always the same, it’s better to use cache or hard code those stuff. Often in laravel, I keep these in a environment of config files. No need to call upon database or any other APIs.
Proper response headers
Don’t accept the improper data. Use accept header in every request. Tell the server what kind of data is acceptable. It leads to filtering of data that can be passed. This way your server does not have to serve requests that they cannot.
Also, respond with status code rather than text. This is much faster because there is less data to transfer.
Compress your data
Always compress textual data using gzip. It means less data to transfer for servers. But don’t over do it. Do not compress data less than 10KB. Learn how to compress data here.
Negotiate the content
Content negotiation is something that happens in API programming. You ask the server what data is required and what data is not required. For example, you can ask for email only in scope, so that server will only send email addresses discarding rest.
Optimize and minify
- Don’t make unnecessary requests. Combine your asset files into one single file.
- Remove unnecessary plugins.
- Optimize the images. The quality of images of 10MB can be reduced to 700KB without loosing much quality for the web.
- Try to retrieve the data separately if not needed immediately like using pagination or lazy loading.
Terminate the application
Application takes up memory space, so try to terminate the application as soon as it is possible.
Use better technologies
- Try to use dedicated servers rather than shared hosting. They are cheap nowadays. Sign Up here for digital ocean. You will get $10 for free.
- Don’t use file based drivers. Consider using the available alternatives like redis or memcached.
- Use Algolia, solr or lucene for search systems. Your database will have less requests to deal with.
- Refer 3rd party scripts to cdn ( content delivery network ). Their servers are generally faster and handle more requests with efficient cache system.
Check out these websites. They open very fast in the browser.
Everything is awesome.