totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

unable to disable js minification #562

Closed DarkKnight1992 closed 7 years ago

DarkKnight1992 commented 7 years ago

i have added this in the config file

allow-compile-js : false

but total is still minifying the js files that don't have ".min." in the name.

I know minifying the files is the best way and that's how it should be done but the problem since we are porting an existing app, the old code is not optimized to be minified and throws a lot of errors.

petersirka commented 7 years ago

I sleep, but you need to use allow-compile-script instead of allow-compile-js. Thank you

DarkKnight1992 commented 7 years ago

wow that was stupid. Thanks a lot

DarkKnight1992 commented 7 years ago

the minification is disabled but a copy of the file is still created in the tmp folder ?

petersirka commented 7 years ago

Yes because the framework expects blocks in the file https://docs.totaljs.com/latest/en.html#pages~Blocks%20(JS%2BCSS%2BHTML)

Is it a problem for you?

DarkKnight1992 commented 7 years ago

yes kinda since we are not using the total's template engine instead using a frontend framework like angular and react which come with their own build engines and we don't want the server to interfer with it at all

petersirka commented 7 years ago

I understand, but is it a problem for you (double creating files in tmp directory)?

DarkKnight1992 commented 7 years ago

well no its not a problem yet but it might become a problem while updating the code on live server, we definitely don't wanna start the server every time we update code. Please correct me if i am wrong

petersirka commented 7 years ago

There is a problem in release mode because static files are cached/use HTTP cache. I created versions file a in the past and this file can rename file without real renaming (it creates virtual rename), documentation: https://docs.totaljs.com/latest/en.html#pages~File%3A%20versions

Other ways:

All advices/ways need to restart app. So we will see, but I'd like to help.

DarkKnight1992 commented 7 years ago

i agree that a great implementation if you are using the total's template engine. But since we are using frontend frameworks, all the modern webpack/rollup build tools do this automatically by saving the hashing and minifyng the files.

Restarting the app is kind of problem since we have different servers in different regions of the world and we use automatic code deployment and its really not productive for us to restart the app on every single server everytime.

Plus aren't we putting pressure on the server to look for all these files when ever they are called instead of using the actual file created by these build tools. Since we are already minifying and hashing their name.

petersirka commented 7 years ago

I have looked into the source-code and the solution is to remove all *.js and *.css files from temporary directory and perform F.touch() method for clearing internal cache. The framework will process again all requested files.

Processing:

But you can create a route for clearing cache:

ROUTE('/internal/update/', function() {

    // Responds with empty response
    this.empty();

    // Clears internal cache
    F.touch();

    // Removess all .js and .css files from TMP
    U.ls(F.path.temp(), function(files) {
        F.unlink(files, NOOP);
        // Now users get all refreshed files
    }, function(filename, isFolder) {
        var ext = U.getExtension(filename);
        return ext === 'js' || ext === 'css';
    });

});

BTW: I'll try to add a skip of creating .js files in tmp directory if the files won't contain blocks or something similar.

DarkKnight1992 commented 7 years ago

yes we can work with a route from clearing the tmp directory for now.

it will great if you can add a config property just like disabling the .js minification instead of skipping the .js creation in tmp directory only for non blocks ?

may be i am being a little ambitious, but is it a possibility ?

petersirka commented 7 years ago

I have added F.config['allow-compile'] which can disable the whole compilation. Try it: $ npm install total.js@beta.

But as I wrote, you will need to perform F.touch() because internal cache contains size and last modification date.

DarkKnight1992 commented 7 years ago

that's great thanks, i will test it and let you know. have also implemented F.touch()

DarkKnight1992 commented 7 years ago

it works perfectly thanks a lot, when is this feature coming in a stable release ?

petersirka commented 7 years ago

Maybe this week. New version will be hotfix.

DarkKnight1992 commented 7 years ago

that's great!!