benhoIIand / grunt-cache-bust

Cache bust static assets using content hashing
MIT License
265 stars 103 forks source link

After Upgrading from 1.4.1 to 1.6.0 the tags in my layout file gets no more busted #236

Closed ThomasTr closed 4 years ago

ThomasTr commented 6 years ago

The Cachebusting for the files works, but the template File gets no more busted.

The cache busting part from my gruntfile:

         cacheBust: {
            options: {
                baseDir: './web/assets/',
                deleteOriginals: true,
                length: 8
            },
            styles: {
                options: {
                    assets: [
                        'css/styles.combined*.css',
                        'js/scripts.combined*.js'
                    ]
                },
                files: [{
                    expand: true,
                    cwd: 'src/AppBundle/Resources/views/',
                    src: ['layout.html.twig']
                }]
            }
        },

The tags to be busted of my layout.html.twig file are:

        <link rel="stylesheet" href="/assets/css/styles.combined.min.css" />
        <script src="/assets/js/scripts.combined.min.js"></script>

Reverted to 1.4.1 and it work again. Are there any relevant changes between these versions?

adam-t-b commented 6 years ago

This is my first time with this specific plugin, so I installed 1.6.0, but could never get the tags in my layout file to bust correctly. Once I installed 1.4.1, they worked great.

My Config:

cacheBust: {
            addTimeStamp: {
                options: {
                    assets: ["Content/css/main.1.0.css", "Content/css/main.2.0.css", "app/compiled.min.js"]
                },
                files: [{
                    src: ["Views/Shared/_Layout.cshtml"]
                }]
            }
        }

My Template:

<html>
<head>
    <link rel="stylesheet" href="~/Content/css/main.1.0.min.css" />
    <link rel="stylesheet" href="~/Content/css/main.2.0.min.css" />
</head>
<body>
    <script src="~/app/compiled.min.js"></script>
</body>

Nothing in the template got replaced with the new hashed file names. I wonder if it has to do with my layout using relative paths?

hemberger commented 6 years ago

I had the same experience as @ThomasTr.

Gruntfile.js

cacheBust: {
    options: {
        jsonOutput: true,
        baseDir: 'htdocs/',
        assets: ['js/**']
    },
    taskName: {
        src: ['templates/Default/engine/Default/preferences.php']
    }
}

Where preferences.php contains the following line:

<script type="text/javascript" src="js/colorpicker.js"></script>

With version 1.6.0, I see the following output:

Running "cacheBust:taskName" (cacheBust) task
>> 1 file busted.

but the preferences.php file is unchanged. However, when I use version 1.4.1 instead, I see:

Running "cacheBust:taskName" (cacheBust) task
>> Busted: templates/Default/engine/Default/preferences.php

And the file is changed to

<script type="text/javascript" src="js/colorpicker.eb1ad786c7a2e593.js"></script>

Thank you to those who pointed me to version 1.4.1, but I am also curious: what has changed in 1.6.0, or what am I doing wrong here? I was pulling my hair out trying to figure out my mistake.

hemberger commented 4 years ago

Note to anyone watching that this is not fixed in release 1.7.0.