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

Enabling both preload and integrity hashes causes double asset download #101

Open
massimilianobraglia opened this issue Dec 10, 2020 · 5 comments

Comments

@massimilianobraglia
Copy link

As you can see in the screenshots below, having both preload and integrity enabled causes issues like double asset download.
This seems to be caused by the tag renderer that does not sets the link header with the integrities.

image
image

@m-vo
Copy link

m-vo commented Feb 25, 2021

I'm facing the same issue. IMHO it's web-link, that must also set integrity="<hash>" on the headers.

At least when doing so, the problem disappears. 😄

It feels these two bundles should not rely too heavily on each other. But they probably would need to a bit if this the right way to fix the issue. Maybe @weaverryan can shed some light on this, then I'll have a go with a PR?

@alexander-schranz
Copy link

alexander-schranz commented Dec 23, 2022

I did also stumble over this issue. I did currently workaround the following way:

webpack_encore:
    preload: false
        {% set assetCss = asset('build/website/app.css') %}
        {% do preload(assetCss, { as: 'style', integrity: app_integrity('website', assetCss) }) %}

        {{ encore_entry_link_tags('app', null, 'website') }}
<?php

namespace App\Twig;

use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class IntegrityExtension extends AbstractExtension
{
    /**
     * @var EntrypointLookupCollectionInterface
     */
    private $entrypointLookupCollection;

    public function __construct(
        EntrypointLookupCollectionInterface $entrypointLookupCollection
    ) {
        $this->entrypointLookupCollection = $entrypointLookupCollection;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction(
                'app_integrity',
                [$this, 'getIntegrity'],
                [
                    'is_safe' => ['html'],
                ]
            ),
        ];
    }

    public function getIntegrity(string $buildname, string $path): string
    {
        $integrityList = $this->entrypointLookupCollection->getEntrypointLookup($buildname)->getIntegrityData();

        return $integrityList[$path];
    }
}

@oleg-andreyev
Copy link

Faced same issue today. Initially wanted to do it manually <link type="preload" but then found that after using encore_entry_css_files or encore_entry_js_files, encore_entry_script_tags and encore_entry_link_tags will not return any results. Then found encore supports preload out-of-the-box but faced current issue.

@joanfabregat
Copy link

According to this comment on Stackoverflow, both the integrity and crossorigin parameters are required on both the Link header and on the <link> tags.

Using Symfony 6.3.2 and Encore 1.17.1 both the parameters are present on the <link> tags:
Screenshot 2023-08-16 at 19 06 00

However only the crossorigin parameter is specified on the Link header:
Screenshot 2023-08-16 at 19 05 55

My current Encore config is:

webpack_encore:
    crossorigin: 'anonymous'
    preload: true

@hracik
Copy link

hracik commented Nov 3, 2023

Having the same issue now with newer symfony/webpack-encore-bundle 2.1.1 and symfony 5.4.

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

6 participants