• Resolved cacsh

    (@cacsh)


    I have activated the built-in minification and manually added all relevant CSS and JS files to the minify settings page. I have tried both memcached and disk cache methods and have tried every combination of embed location and embed type, but no matter what I try, the original CSS and JS files remain in the page source for all pages and no minified assets are added to the page at all.

    I have checked the cache directory on the server and although the minify directory is created and has the correct ownership and permissions, the minified files themselves are not created in the directory.

    I have ensured all assets are added by path only (e.g. wp-includes/js/jquery/jquery.js rather than https://example.com/wp-includes/js/jquery/jquery.js) and I have removed all query strings from the asset paths.

    Activating minification debugging prints a comment with the following:

    Object Caching 0/1374 objects using memcached
    Page Caching using memcached (User is logged in) 
    Lazy Loading
    Minified using memcached
    
    Minify debug info:
    Theme:              26956
    Template:           index

    Is there anything else I can try to get the minify functionality working?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @cacsh

    I m sorry about the issue you are experiencing and I am happy to assist you with this.
    Can you please share your website URL and the screenshot of the settings in Perfomance>Minify?
    Thanks!

    Thread Starter cacsh

    (@cacsh)

    Hi @vmarko thanks for your help.

    The website is https://development.device5.co.uk/durance

    Here are screenshots of the W3 settings:

    https://ibb.co/5jNG2kJ
    https://ibb.co/WGXsxg8

    Thanks again

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @cacsh

    Thank you for providing the additional information.
    The problem is the rewriting of URL structure. So you should enable the “Rewrite URL structure” option in Performance>Minify>General because If disabled, CSS and JS embeddings will use GET variables instead of “fancy” links.
    Make sure to save all settings and purge the cache once you enable the option.
    Thanks!

    Thread Starter cacsh

    (@cacsh)

    Hi Marko, thanks for the advice. I have made this change in the settings and can see the nginx.conf file has updated, but unfortunately nothing has changed on the front-end of the site.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @cacsh

    the website URL you shared is not correct.
    Please share the correct website URL.
    Thanks!

    Thread Starter cacsh

    (@cacsh)

    Hi Marko, the website URL is correct – it redirects to the correct live site that is having the minification issue.

    I have made the changes to the URL setting and have tried switching between memcached and disk settings but the situation is the same, all original CSS and JS remain in the page source and no minified files are generated in the minify cache directory (when using the disk setting).

    Some info which might be useful is that I have wordpress core in a separate directory to wp-content. I don’t think this should make a difference because all other plugins work correctly and W3 itself has put the cache and minify directories in the right place, but I mention it in case it is useful.

    My directory structure is:

    webroot
    |
    |-wp-content
    |
    |-wordpress
    |
    |-index.php
    |-wp-config.php

    with global vars indicating the location of wordpress and wp-content.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @cacsh

    Please check the screenshot below:

    Thanks!

    Thread Starter cacsh

    (@cacsh)

    Apologies! Please try the URL again. It should work now

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,
    Thank you for the information.
    Can you please check your nginx.conf, make sure the rules are in the nginx.conf (you can find the rewrite rules in Performance>Install) and make sure to restart the nginx.
    Thanks!

    Thread Starter cacsh

    (@cacsh)

    Thanks Marko. Here is the nginx.conf:

    # BEGIN W3TC Minify cache
    location ~ /wp-content/cache/minify/.*js_gzip$ {
        gzip off;
        types {}
        default_type application/x-javascript;
        add_header Content-Encoding gzip;
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Referrer-Policy "no-referrer-when-downgrade";
        add_header Vary "Accept-Encoding";
    }
    location ~ /wp-content/cache/minify/.*css_gzip$ {
        gzip off;
        types {}
        default_type text/css;
        add_header Content-Encoding gzip;
        expires 31536000s;
        etag on;
        if_modified_since exact;
        add_header Referrer-Policy "no-referrer-when-downgrade";
        add_header Vary "Accept-Encoding";
    }
    # END W3TC Minify cache
    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    location ~ \.(css|htc|less|js|js2|js3|js4)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        etag on;
        if_modified_since exact;
        try_files $uri $uri/ /index.php?$args;
    }
    add_header Referrer-Policy "no-referrer-when-downgrade";
    # END W3TC Browser Cache
    # BEGIN W3TC Minify core
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    if (-f $request_filename$w3tc_enc) {
        rewrite (.*) $1$w3tc_enc break;
    }
    rewrite ^/wp-content/cache/minify/ /index.php last;
    # END W3TC Minify core

    I have checked that the nginx.conf file is included in the main domain config file (it is) and have restarted nginx, but unfortunately there is no change in page output and no minified assets are generated.

    • This reply was modified 4 years ago by cacsh.
    Thread Starter cacsh

    (@cacsh)

    Some extra info: I am now seeing an error on the minify settings page that says:

    W3 Total Cache error:It appears Minify URL rewriting is not working. Please verify that all configuration files are included in the configuration file (and that you have reloaded / restarted nginx).
    Unfortunately minification will not function without custom rewrite rules. Please ask your server administrator for assistance. Also refer to the install page for the rules for your server.
    Technical info
    nginx configuration file contains rules to rewrite url /wp-content/cache/minify/1461003423w3tc_rewrite_test.css. If handled by plugin, it returns "Minify OK" message.
    The plugin made a request to /wp-content/cache/minify/1461003423w3tc_rewrite_test.css but received:
    A valid URL was not provided.
    instead of "Minify OK" response. 

    However, visiting the /wp-content/cache/minify/1461003423w3tc_rewrite_test.css URL does indeed display “Minify OK”.

    Thread Starter cacsh

    (@cacsh)

    Further update, the URL that is being checked here is literally:

    /wp-content/cache/minify/1461003423w3tc_rewrite_test.css

    this is failing because it isn’t a proper URL. If I add a filter to w3_filename_to_url I can change these paths to full URLs and then the minify check works.

    Minification is still broken though as no assets are generated and all original CSS and JS remain in the page.

    Thread Starter cacsh

    (@cacsh)

    The hunt continues. It looks like the cause is due to an issue with the theme W3 thinks is active.

    Minify debugging comments in the front-end pages show the theme hash as 26956 whereas on the admin pages, the theme hash of the actual active theme is cfdf7. Because of this, the minification code never runs – W3 never thinks the right theme is active.

    Also, when using the help wizard to add assets to minification settings, it guesses the parent theme name rather than the actually active theme. Could this be related to the issue?

    • This reply was modified 4 years ago by cacsh.
    Thread Starter cacsh

    (@cacsh)

    Confirmed. So on admin/front-end pages I see the following:

    Admin:
    theme root: /var/www/xyz
    template: parent-theme
    stylesheet: active-theme

    Front-end:
    theme root: /var/www/xyz
    template: active-theme
    stylesheet: active-theme

    This leads to different hashes for the same theme on front/back end of the site, preventing minification from working.

    • This reply was modified 4 years ago by cacsh.
    Thread Starter cacsh

    (@cacsh)

    Okay so it turns out a previous developer didn’t know how to use WordPress’s get_template_directory / get_stylesheet_directory and had just edited the template row in wp_options directly so template was set to the child directory!

    Once that was fixed, template and stylesheet return the correct values, the correct hashes are generated that match on front/back-end and the plugin works as it should.

    There was no issue at all with W3 Total Cache.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Minified assets not being added to the page’ is closed to new replies.