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] Localize assets from CDNs #2

Closed
3 of 5 tasks
tabacitu opened this issue Oct 27, 2021 · 5 comments
Closed
3 of 5 tasks

[v2] Localize assets from CDNs #2

tabacitu opened this issue Oct 27, 2021 · 5 comments
Assignees

Comments

@tabacitu
Copy link
Member

tabacitu commented Oct 27, 2021

This same package could/should also solve the problem of localizing CDN assets.

We could add:

  • a config variable, so that the dev can choose his assets to be automatically localized (or not);
  • when an item is first loaded, if that asset is from a CDN (we know that because it begins with http://, https:// or ://), we check if it doesn't also exist on the local file system (storage/app/public/assets/localized/);
    • if it's been localized, we use the local path instead;
    • if it has NOT been localized, we add that asset to a queue of files to be localized;
  • when running the queue, if the file hasn't been localized in the meantime, each CDN file will be pulled from the CDN and put into storage/app/public/assets/localized/ so it can be used from there next time;

After that, the docs could also have a section with something like:

// FOR ASSETS FROM CDNs
@asset('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js')
// will output <link href="{{ asset('https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js')"> the first time
// and it will add 'https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js' to a queue of files to be downloaded;
// after that queue has been run (you choose how often), the file has been "localized", which means it's
// also available in your /public/assets/localized/cdn.jsdelivr.net/npm/axios/dist/axios.min.js
// so this package will just load it from there instead, by outputting
// will output <link href="{{ asset('assets/localized/cdn.jsdelivr.net/npm/axios/dist/axios.min.js')">
//
// This has HUUUGE power, because now you can use CDN assets just like they were local. You do NOT have to
// provide them in your public directory, this package will do it for you.
@tabacitu tabacitu changed the title Localize assets from CDNs [v2] Localize assets from CDNs Oct 27, 2021
@tabacitu
Copy link
Member Author

We should probably also provide a way to localize ALL assets. Packages could provide a way to tell AssetManager directories where they hold blade files that use assets from CDNs. Then when you run php artisan assets:localize it would have a list of directories, go through all the blade files there, parse them to get URLs and localize everything in one command.

@tabacitu
Copy link
Member Author

Brain dump with @promatik

@basset('https://cdnjs.cloudflare.com/ajax/libs/tinymce/6.2.0/tinymce.min.js')

/public/basset/cdnjs.cloudflare.com/ajax/libs/tinymce/6.2.0/tinymce.min.js

---

php artisan basset:install
- add to .gitignore
- add to composer.json

php artisan basset:internalize

@tabacitu
Copy link
Member Author

@promatik
Copy link
Collaborator

promatik commented Nov 21, 2022

Can't wait to do it 🙌

@promatik
Copy link
Collaborator

promatik commented Dec 4, 2022

This is fixed by #14

@tabacitu tabacitu closed this as completed Dec 6, 2022
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