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

Allow remote asset URLs & empty favicon fix #183

Merged
merged 3 commits into from
Mar 9, 2020

Conversation

markokeeffe
Copy link

@markokeeffe markokeeffe commented Nov 21, 2019

There are two parts to this PR :

  1. Added support for remote asset URLs when adding assets with LaRecipe::script() or LaRecipe::style()
  2. Fixed issue where favicon links are added to the template when the config option larecipe.ui.fav is empty (default value)

Part 1 - Remote Asset URLs
Our product uploads all of our built assets to a CDN on deployment. We add assets to LaRecipe through a service provider like so:

        // Add js scripts that will be injected into the larecipe layout
        $scripts = webpack_mix_collection(['larecipe', 'larecipeStyles'], 'js');
        foreach ($scripts as $key => $script) {
            LaRecipe::script('larecipe-' . $key, cdn_asset($script));
        }

        // Add css styles that will be injected into the larecipe layout
        $styles = webpack_mix_collection(['larecipeStyles'], 'css');
        foreach ($styles as $key => $style) {
            LaRecipe::style('larecipe-' . $key, cdn_asset($style));
        }

There is a massive performance improvement if LaRecipe can simply add the remote URL as the src of the scripts/styles instead of routing through the ScriptController/StyleController endpoints.

I wasn't sure if this feature should be switched on/off through a config option. Let me know if you think I should add that.

Part 2 - Favicon Fix
I noticed that with the default value of '' for the larecipe.ui.fav config option, the template still added the <link rel="apple-touch-icon" /> and <link rel="shortcut icon" /> tags, which caused the browser to make requests to the root URL of our application. The fix makes these conditional based on the config value not being falsey.

@saleem-hadad
Copy link
Owner

Thank you @markokeeffe for your contribution, but I don't like the idea of switching the file loading from the config file, I think LaRecipe should be more cleaver to detect that on the fly. I'll think of a different solution for this issue.

@markokeeffe
Copy link
Author

Hi @saleem-hadad, I'm not sure what you mean. There are no changes to the config files in this PR.

I probably should have done this as two pull requests. Happy to split them up if you like.

The asset URL fix does not require anything in the config file.

The favicon fix just looked like a missing check in the template, I haven't changed any config options.

@saleem-hadad saleem-hadad merged commit 0544854 into saleem-hadad:master Mar 9, 2020
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.

2 participants