{"id":11984,"date":"2022-04-12T10:00:00","date_gmt":"2022-04-12T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=11984"},"modified":"2022-04-12T10:14:43","modified_gmt":"2022-04-12T01:14:43","slug":"6-tips-for-optimizing-a-laravel-application","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/11984","title":{"rendered":"6 Tips for optimizing a laravel application"},"content":{"rendered":"\n<p>Today, I would like to share about some tips for optimizing a laravel application. Let&#8217;s take a look.<\/p>\n\n\n\n<p><strong>1. Cache routes, config and views<\/strong><\/p>\n\n\n\n<p>Caching speeds up your application. This is important when deploying a application to a production environment.<\/p>\n\n\n\n<p>To cache your routes, you can use the following command:<br>php artisan route:cache<\/p>\n\n\n\n<p>To clear the route cache, you can use the following command:<br>php artisan route:clear<\/p>\n\n\n\n<p>To cache config, you can use the following command:<\/p>\n\n\n\n<p>php artisan config:cache<\/p>\n\n\n\n<p>To cache your views, you can use the following command:<\/p>\n\n\n\n<p>php artisan view:cache<br><br><strong>2. Remove unused services<\/strong><\/p>\n\n\n\n<p>You should remove unused services when the application grows. This can be done by removing the service from the config\/app.php file.<\/p>\n\n\n\n<p><strong>3. Remove unused packages <\/strong><\/p>\n\n\n\n<p>To keep the app clean, you should remove unused packages from the application. This can be done by removing the package from the composer.json file or by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">composer remove package-name<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>4. Remove development dependencies<\/strong><\/p>\n\n\n\n<p>You should also remove development dependencies when deploying to production. This can be done by running the following command:<\/p>\n\n\n\n<p>composer install &#8211;prefer-dist &#8211;no-dev -o<\/p>\n\n\n\n<p><strong>5. Composer Autoload Optimization<\/strong><\/p>\n\n\n\n<p>For your applications, you should use the composer autoload optimization feature as the autoloader can take significant time for each request:<\/p>\n\n\n\n<p>composer dumpautoload -o<\/p>\n\n\n\n<p>The -o flag will convert PSR-0\/4 autoloading to classmap to become a faster autoloader.<\/p>\n\n\n\n<p><strong>6. Precompile your assets<\/strong><\/p>\n\n\n\n<p>If npm is used for your front-end development, you should precompile your assets. This can be done by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm run production<\/pre>\n\n\n\n<p>This will compile the assets and create public\/assets directory.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>This is all for now. Hope you enjoy that.<\/p>\n\n\n\n<p>By Asahi<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11984\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/11984\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"6 Tips for optimizing a laravel application\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11984\" data-text=\"6 Tips for optimizing a laravel application\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11984\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11984\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today, I would like to share about some tips for optimizing a laravel application. Let&#8217;s take a look. 1. [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11984"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=11984"}],"version-history":[{"count":3,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11984\/revisions"}],"predecessor-version":[{"id":11988,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11984\/revisions\/11988"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=11984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=11984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=11984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}