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

Assets not registering on FE #176

Closed
jsmrtn opened this issue Feb 24, 2020 · 5 comments
Closed

Assets not registering on FE #176

jsmrtn opened this issue Feb 24, 2020 · 5 comments
Labels
bug Something isn't working

Comments

@jsmrtn
Copy link

jsmrtn commented Feb 24, 2020

Describe the bug

We are using Blitz Cache to import our include that loads a plugin called adWizard {{ craft.blitz.getTemplate('ism/includes/_adwizard') }}. The include is pretty much some divs and the init for adWizard i.e. {{ craft.adWizard.randomizeAdGroup('leaderboard') }}

However, it's not registering the asset bundles correctly on the front end. If I default back to the standard {% include %} tags the assets get loaded in correctly, so I can only assume Blitz is doing something weird when it runs the getTemplate code.

Thanks!

To reproduce

Steps to reproduce the behaviour:

  1. Use a plugin that registers assets onto the front end
  2. Include a template that calls said plugin through getTemplate

Expected behaviour

Assets to be registered on the front end

Versions

  • Plugin version: 3.4.1
  • Craft version: 3.4.6.1
@jsmrtn jsmrtn added the bug Something isn't working label Feb 24, 2020
@bencroker
Copy link
Collaborator

How are the asset bundles being generated? Can you show the code of your injected template?

I'm not sure if this is related, but note that a limitation of injecting the result of an AJAX request into HTML is that any script tags will not be executed. This may have adverse effects on injected content that includes JavaScript code to be run.

@jsmrtn
Copy link
Author

jsmrtn commented Feb 24, 2020

They're added by the plugin using $view->registerAssetBundle(FrontEndAssets::class);

Our include is super simple, and doesn't register the asset bundle itself directly.

<div class="adpanel mt--large pt--xlarge pr--medium pb--xlarge pl--medium">
    <div class="site-content">
        {% if craft.app.request.isMobileBrowser %}
            {% if craft.adWizard.randomizeAdGroup('mpu') | length %}
                {{ craft.adWizard.randomizeAdGroup('mpu') }}
            {% else %}
                {{ craft.adWizard.randomizeAdGroup('leaderboard') }}
            {% endif %}
        {% else %}
            {{ craft.adWizard.randomizeAdGroup('leaderboard') }}
        {% endif %}
    </div>
</div>

Ref your second point, we've made use of your afterBlitzInject call before, but these assets don't run on runtime, they contain functions that gets referenced by the output of the randomizeAdGroup variable.

@bencroker
Copy link
Collaborator

bencroker commented Feb 24, 2020

Just ran some tests and I see that the asset bundles are indeed not returned when using craft.blitz.getTemplate, but they are returned when using craft.blitz.getUri (provided there are body tags in the template, works with public templates only). Even when they are returned though, this doesn't help the fact that the asset bundles are JavaScript files that, as noted above, will not run after being injected into the DOM.

I know that @lindseydiloreto has been adding cache-proofing to his plugins lately and have asked him if Ad Wizard might get an update soon.

@jsmrtn
Copy link
Author

jsmrtn commented Feb 24, 2020

Even when they are returned though, this doesn't help the fact that the asset bundles are JavaScript files that, as noted above, will not run after being injected into the DOM.

Ah yes, of course.

I did have a request open over at the repo for this doublesecretagency/craft-adwizard#9, I guess this is more an adwizard issue than a Blitz issue, as this is just how Blitz works?

@bencroker
Copy link
Collaborator

Yes, the way you've manually hooked it up on the front-end is probably your best bet for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants