Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Frontend
  4. Creating Page-Specific CSS/JS
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia
  • Multiple Entries Per Page?

Creating Page-Specific CSS/JS

Edit this page

Warning: You are browsing the documentation for Symfony 4.3, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

Creating Page-Specific CSS/JS

If you're creating a single page app (SPA), then you probably only need to define one entry in webpack.config.js. But if you have multiple pages, you might want page-specific CSS and JavaScript.

To learn how to set this up, see the Encore: Setting up your Project example.

Multiple Entries Per Page?

Typically, you should include only one JavaScript entry per page. Think of the checkout page as its own "app", where checkout.js includes all the functionality you need.

However, it's pretty common to need to include some global JavaScript and CSS on every page. For that reason, it usually makes sense to have one entry (e.g. app) that contains this global code (both JavaScript & CSS) and is included on every page (i.e. it's included in the layout of your app). This means that you will always have one, global entry on every page (e.g. app) and you may have one page-specific JavaScript and CSS file from a page-specific entry (e.g. checkout).

Tip

Be sure to use split chunks to avoid duplicating and shared code between your entry files.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Become certified from home

Become certified from home

Symfony Code Performance Profiling

Symfony Code Performance Profiling

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Adrien Peyre, a Symfony contributor

Thanks Adrien Peyre for being a Symfony contributor

1 commit • 4 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia