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

[9.x] Use Relative View Path Name When Hashing Compiled Views #39642

Conversation

bogdankharchenko
Copy link
Contributor

@bogdankharchenko bogdankharchenko commented Nov 17, 2021

Issue

We are not able to "pre-compile" views on say a local machine/build box, and push it into prod "pre-compiled". This is because the filename of the cached view is a sha1 of the absolute path of the file. Meaning, if the directory is different on which the view was initially compiled, then the view is then recompiled.

This PR introduces a new basePath param into the the Compiler - which then allows us to take the absolute path of the view, and remove the base path from it - which is then used as the "name" before being hashed

Targeted into 9.x as this is a possible breaking change.

Driver behind this was during a vapor deploy, we can pre-compile the views (locally) into bootstrap/cache/views and serve them already compiled. Which is great for a read-only filesystem.

@dennisprudlo
Copy link
Contributor

Why not simply call view:cache as part of the deployment process?

@bogdankharchenko
Copy link
Contributor Author

@dennisprudlo yes I already do that. But this will allow for the ability to pre-compile views before packaging the app up in a container or deploying to read only file systems

@inxilpro
Copy link
Contributor

I could definitely also see using this in a CI pipeline to pre-compile views before deploy.

@taylorotwell
Copy link
Member

Please detail the breaking changes.

@bogdankharchenko
Copy link
Contributor Author

@taylorotwell thinking more about this -- I actually do not see the breaking change anymore, as the basePath is now an optional param defaulting to an empty string.

Would you like me to retarget this into 8.x?

@taylorotwell
Copy link
Member

I placed this behind a new view.relative_hash configuration option to minimize risk of breakage. Defaults to false.

@taylorotwell taylorotwell merged commit aa2a02d into laravel:master Nov 17, 2021
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

Successfully merging this pull request may close these issues.

4 participants