2

Sometimes I only need to change one static file, is it possible to do that?

Example I have changes to: /static/versionxxxxxxxx/frontend/Superlove/custom/da_DK/Magento_PageCache/js/page-cache.js

Can I just manually change it and do System > Cache Management > Flush JavaScript/CSS in the admin?

1 Answer 1

2

No. In Magento2 every static file (served from pub/static folder) is generated by setup:static-content:deploy method in bin/magento script (or generated on the fly in developer mode). This file usually is a link to a file inside module skin folder but I noticed it is not always the case, sometimes the file is copied. In both cases the change done to the file might get reverted. In the first case if module is kept in vendor folder and is reinstalled by composer install action or in second when setup:static-content:deploy is called another time. If you want to make changes to file from a module you can do this in 2 ways:

1) copy the file to the theme folder and make changes there. It will be available only in that theme. In you example, assuming you have magento installed via composer packages, copy filde vendor/magento/module-page-cache/view/frontend/web/js/page-cache.js to app/design/frontend/Superlove/custom/Magento_PageCache/js/page-cache.js and edit file in app/design folder. If you have magento installed in app/code then the path should be app/code/Magento/Page_Cache/view/frontend/web/js/page-cache.js

2) In a custom module create file view/frontend/web/requirejs-config.js with similar content

var config = {
    map: {
        '*': {
            pageCache:  'Custom_Module/js/page-cache'
        }
    }
};

and in view/frontend/web/js/page-cache.js create the file by copying content of original file and modifying it to your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.