-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Make minify rename javascript variables to make javascript even shorter #7311
Comments
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
I think this is still relevant and valuable because it can make pages load faster. |
This has been implemented in https://github.com/tdewolff/minify/releases/tag/v2.9.0 and you should be able to update the minify package manually. Currently Hugo doesn't use the latest version of minify that has this feature. |
Is there a plan to integrate this update into hugo? Or shall we go with manual update still? |
@bep, I think we can evaluate updating minify again. To recap the situation: We updated from v2.6.2 to v2.9.4 in #7701, but that was reverted in #7792 after this report from the forums. I was able to reproduce the issue at the time but couldn't identify the root cause. Today, I took another look at the issue reported in the forum, and the problem is fixed in v2.9.9 (specifically, tdewolff/minify@eb4ff2b). |
I guess this issue is talking about the https://gohugo.io/hugo-pipes/js#import-js-code-from-assets As to updating the upstream minifier. We have had a couple of breaking changes with this recently, and the problem with these breaks is that they don't just put a scratch in your site. We currently don't have a good enough test suite on the Hugo side of the fence to make sure that all is OK, so upgrades requires manual work, and this has not been a priority of me lately. |
I though about that too. I have been checking the code proposed by @kssilveira with these 2 methods:
The output is the same as the one mentioned in the issue in both cases. |
No, I meant something like this: {{ $js := resources.Get "test.js" }}
{{ $jsm := $js | js.Build (dict "minify" true) }} |
Yes, that one renames variables correctly |
Thanks, Another use case I have for this is to call I ran into a few problems:
I was experimenting with:
And the idea was to do:
|
This worked (after creating the file inside
|
Also interested in this. That would be a good workaround to the upstream minifier issue, at least for my setup. |
The problems that @bep mentions are ones from a long time ago and have been fixed since. Using the updated The lack of tests in Hugo for the minifier was what was holding back the upgrade, however is there such a test set for |
1) We are now using tdewolff/minify 2.9.22 (latest). 2) The default configuration is 3) As JS, this: function init() {
var nodes = document.getElementsByTagName('iframe');
for (var i = 0; i < nodes.length; i++) {
var data = nodes[i].getAttribute('data-src');
if (data) {
nodes[i].setAttribute('src', data);
}
};
}
setTimeout(init, 1500); is minified to this: function init(){for(var b=document.getElementsByTagName('iframe'),a=0,c;a<b.length;a++)c=b[a].getAttribute('data-src'),c&&b[a].setAttribute('src',c)}setTimeout(init,1500) 4) As an HTML file, this: <script>
function init() {
var nodes = document.getElementsByTagName('iframe');
for (var i = 0; i < nodes.length; i++) {
var data = nodes[i].getAttribute('data-src');
if (data) {
nodes[i].setAttribute('src', data);
}
};
}
setTimeout(init, 1500);
</script> is minified to this: <script>function init(){for(var b=document.getElementsByTagName('iframe'),a=0,c;a<b.length;a++)c=b[a].getAttribute('data-src'),c&&b[a].setAttribute('src',c)}setTimeout(init,1500)</script> Unless I'm missing something, this was resolved a while ago. |
The minifier does not rename variables that could be referenced outside the script, i.e. all global variable names are kept even as As for @jmooring the JS example looks correct, but the HTML example not, is the JS minifier enabled in that case? It should be! |
@tdewolff Thank you. You are correct. I have updated my comment. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
If I minify javascript using yui-compressor:
I get
If I use hugo --minify, I get:
This request is to make hugo --minify rename javascript variables to make javascript even shorter.
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
I think I have the latest release.
The text was updated successfully, but these errors were encountered: