মূল কনটেন্টে যান
🐹
emberjs learning
গাইড•1 · Route Loading and Data Fetching

Use Route-Based Code Splitting

impact · CRITICAL30-70% initial bundle reductionplan · দিন ০৩৪
আগে নিজে — এই কোডে কী ভুল, ঠিকটা কেমন হবে?

Incorrect (everything in main bundle):

// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {
    // No optimization
  });

  return app.toTree();
};
পুরো rule · Correct আর ব্যাখ্যা — আগে নিজে লিখুন, তারপর খুলুন

With Embroider's route-based code splitting, routes and their components are automatically split into separate chunks, loaded only when needed.

Incorrect (everything in main bundle):

// ember-cli-build.js
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {
    // No optimization
  });

  return app.toTree();
};

Correct (Embroider with Vite and route splitting):

// ember-cli-build.js
const { Vite } = require('@embroider/vite');

module.exports = require('@embroider/compat').compatBuild(app, Vite, {
  staticAddonTestSupportTrees: true,
  staticAddonTrees: true,
  staticHelpers: true,
  staticModifiers: true,
  staticComponents: true,
  splitAtRoutes: ['admin', 'reports', 'settings'], // Routes to split
});

Embroider with splitAtRoutes creates separate bundles for specified routes, reducing initial load time by 30-70%.

Reference: Embroider Documentation