Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DanielRønfeldt's avatar

Low performance index on Pagespeed Insights

Hey guys,

I'm getting a low Pagespeed performance index (42 for mobile and 69 for desktop) on a Laravel 10 Inertia + Vue 3 project. The worst offender (in Google's opition) seems to be app-*.js which is 299 kB in filesize (gzipped is 99 kB). The project is also using the Facebook sharing SDK, as well as the Google Tag Manager script, which, of course, PageSpeed is complaining about , too :) The project is hosted on a fvery ast DigitalOcean server, with Cloudflare DNS, in case this is relevant.

I was wondering, what can I do in order to "reduce unused javascript", as per Google's suggestion? Thanks a lot!

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue of low performance index on PageSpeed Insights for your Laravel 10 Inertia + Vue 3 project, you can take several steps to optimize your JavaScript and overall page load performance. Here's a list of strategies you can employ:

  1. Analyze Bundle Size: Use tools like Webpack Bundle Analyzer to understand what's taking up space in your app-*.js bundle. This can help you identify large libraries or chunks of code that might not be necessary.

  2. Code Splitting: Implement code splitting in your Vue application. This allows you to split your code into smaller chunks which can be loaded on demand. Vue 3 and Webpack support dynamic imports out of the box.

    const MyComponent = () => import('./MyComponent.vue');
    
  3. Tree Shaking: Ensure that your build process supports tree shaking, which is a way to remove unused code from your final bundle. Using ES6 module syntax (import and export) helps with this.

  4. Lazy Load Routes: If you're using Vue Router, consider lazy loading your routes. This means that the component for a route will only be loaded when the user navigates to that route.

    const Home = () => import('./views/Home.vue');
    const routes = [
      { path: '/', component: Home }
    ];
    
  5. Optimize Dependencies: Review and potentially remove or replace heavy third-party libraries. Sometimes there are lighter alternatives that can do the job.

  6. Minify and Compress: Ensure that your JavaScript files are being minified and compressed. Gzipping is good, but also consider Brotli compression, which can offer better compression ratios.

  7. Cache Assets: Use HTTP caching headers to cache assets on the user's browser. Cloudflare can help with this, but make sure you have the correct settings.

  8. Remove or Defer Non-Essential Scripts: The Facebook SDK and Google Tag Manager can significantly affect performance. Load them asynchronously or defer their loading to after the main content has been rendered.

    <script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'GA_MEASUREMENT_ID');
    </script>
    
  9. Use Web Workers: If there are heavy computations, consider moving them to a Web Worker to run them in a separate thread.

  10. Monitor Performance: Continuously monitor your app's performance with tools like Lighthouse and make improvements iteratively.

  11. Server-Side Performance: Ensure that your server-side rendering (if applicable) is optimized. This includes optimizing database queries, using proper caching strategies, and minimizing server response times.

  12. Content Delivery Network (CDN): Since you're already using Cloudflare, ensure that it's configured to serve your assets from the nearest geographical location to your users.

Implementing these strategies should help reduce unused JavaScript and improve your PageSpeed score. Remember that optimization is an ongoing process, and it's important to regularly profile and monitor your application's performance.

Please or to participate in this conversation.