Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load encore compiled js files in third party app #1271

Open
maciejregula opened this issue Jun 28, 2024 · 2 comments
Open

How to load encore compiled js files in third party app #1271

maciejregula opened this issue Jun 28, 2024 · 2 comments

Comments

@maciejregula
Copy link

maciejregula commented Jun 28, 2024

Hi,

I have application where some js files need to be loaded by third party app so there is no "encore_entry_script_tags" function to load js files. I have two entrypoints in my encore configuration:

    builds:
        admin: '%kernel.project_dir%/public/admin/build'
        front: '%kernel.project_dir%/public/front/build'

My admin app (REACT + SYMFONY) uses the admin build so I can load my js builds via "encore_entry_script_tags".
However, the front build should be loaded by a third-party application and there is not possible to use "encore_entry_script_tags". Is it possible to keep encore build in one js file with specific given name so it can be easily loaded via regular <script type="text/javascript" src"" /> ?

@maciejregula maciejregula changed the title How to load compiled scripts via encore in third party app How to load encore compiled js files in third party app Jun 28, 2024
@stof
Copy link
Member

stof commented Aug 30, 2024

It is possible:

  • disable the splitting of entry points (i.e. don't use Encore.splitEntryChunks() in your config), so that each entrypoint stays as a single file
  • disable versioning of assets so that the content hash does not get included in the file name
  • figure out your own solution for caching (versioning of assets makes things compatible with long term caching of assets automatically, as the URL would change when the content change)

@stof
Copy link
Member

stof commented Aug 30, 2024

Alternatively, you could keep the versioning of assets for the build and build a controller in your Symfony application that would redirect from /front.js to the appropriate versioned asset (allowing to keep a long cache for the versioned asset and all dynamic chunks of the build)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants