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

v2 - named assets, no more symlink, caching features #142

Merged
merged 18 commits into from
Nov 21, 2024
Merged

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Oct 23, 2024

refs: #140
The basset refactor PR.

What's new? (Summary)

  • Changed the default disk to be the basset disk, it points to the /public folder instead of storage, removing the need for symlink.
  • removed the composer script to link the storage
  • added an option to cache urls when dev mode is on.
  • install command now adds public/{basset_path} to .gitignore
  • local files are only "re-cached" in dev mode when their content hash changes
  • introduced "named assets" through a map function
  • added ability to change the package named assets

Removing the symlink and adding .gitignore

This had been an issue for some of the users. The mangle between filesystem, permissions and symlinks had been a source of problems.
This PR removes the need for symlinking because the assets will be cached in the /public folder. Since the public folder is not .gitignored by default, the install command now adds the basset folder to the gitignore.

Cache URL's in dev mode

One painpoint of using basset in development was that you couldn't cache the http dependencies (usually cdns) and keep your "local" files "uncached", so that you could work developing your admin panel without internet access.
In this PR we introduce the force_url_cache, that will cache the urls even when you are in dev mode. That way it's possible to cache everything in advance with php artisan basset:cache, or at the required time when the asset is saw on the page for the first time.

Local files (recaching issues)

While working locally, all local assets (eg, vendor/backpack/crud/resources/assets/css/common.css) were "re-cached" on every request. That was required to make the assets available "for public" usage (the vendor folder is not accessible).
In this PR we introduced an "hash" that we store alongside the local files in the file map. That way, we only need to "re-cache", the ones were the content changed.

Named Assets

This is the block muscle of this PR. By using named assets we unlocked a lot of other possibilities.
The concept is simple, packages (like backpack/crud), register their named assets with Basset::map(), when refering to those packages, developers can use only @asset('asset-package-name').
The advantages of this approach are:

  • packages that use the same asset in multiple places (eg: select2 in 10+ files), just need to update the Basset::map() definition in 1 place, ensuring that no package conflicts occur by using multiple versions of the same package.
  • the usage of "variables" in assets was not possible. With named assets, developers can register in advance the "possible" variables, so that no "on-the-fly" caching happens.
  • When a package version change, we can delete the previous version, and get the new one.

All this now enables the workflow of publishing your assets to your repo, removing the need for calling php artisan basset:cache in production. Or by using a combination of both, and just calling :cache without :clear, so only the "changed" assets will be cached. If nothing changed, no assets are "re-cached".

@pxpm pxpm changed the base branch from main to next November 21, 2024 12:56
@pxpm pxpm changed the title [WIP] v2 v2 - named assets, no more symlink, caching features Nov 21, 2024
@pxpm pxpm added the v7 label Nov 21, 2024
@pxpm pxpm merged commit 54bb591 into next Nov 21, 2024
5 checks passed
@pxpm pxpm deleted the remove-symlink branch November 21, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants