WordPress.org

Ready to get started?Download WordPress

Forums

WP-LESS
[resolved] updating cache when @imported files change (6 posts)

  1. Steve Taylor
    Member
    Posted 2 years ago #

    I'm bundling WP-LESS with a theme I've developing, and so far it works great - many thanks.

    My only issue so far is that if I have, say, main.less, which is enqueued, and this @imports vars.less, when I change vars.less the cache doesn't update. I have to make a change to main.less for the cache to update.

    I don't see this as a critical issue at the moment, because updates to global includes like vars.less aren't too frequent, but it can be annoying. Are there any plans to update the cache when @imported files are changed?

    http://wordpress.org/extend/plugins/wp-less/

  2. jancbeck
    Member
    Posted 2 years ago #

    I'm also noticing this minor issue while developing. But finding changes in imported less files could be a litte bit tough to spot since the only connection WP-LESS has to those files is made via enqueue style to your main file that contains your imports. WP-LESS would need to parse and watch for those imported files separately which seems a bit out of reach to me.

    The easiest way to speed up my workflow was to force compile all files on every page call:

    <?php
    function always_compile_less() {
    	global $WPLessPlugin;
    	$WPLessPlugin->processStylesheets( true ); // force compile
    }
    add_action( 'wp', 'always_compile_less' );

    This takes a bit less than a second to compile twitter bootstrap 2.1 on every pageload on my system but should definitely not be enabled on a live system.

  3. Steve Taylor
    Member
    Posted 2 years ago #

    Thanks for the tip Jan, good thinking. You're right, it does seem to be something that can't be easily addressed in the plugin itself.

    I use the WP_LOCAL_DEV constant to signal dev environments (http://markjaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/), so this is what I'm doing:

    add_action( 'after_setup_theme', 'my_setup' );
    function my_setup() {
    	add_action( 'wp_print_styles', 'my_process_less' );
    	add_action( 'admin_print_styles', 'my_process_less' );
    }
    
    function my_process_less() {
    	global $WPLessPlugin;
    	$WPLessPlugin->processStylesheets( WP_LOCAL_DEV );
    }
  4. jancbeck
    Member
    Posted 2 years ago #

    This is great. I was also thinking about a little refinement

    function always_compile_less() {
    	global $WPLessPlugin;
    	$WPLessPlugin->processStylesheets( true ); // force compile
    }
    if( WP_DEBUG )
    	add_action( 'wp', 'always_compile_less' );

    to prevent this from running in a live environment.

  5. jancbeck
    Member
    Posted 1 year ago #

    Happy to see that in the latest version of the plugin less is always compiled when WP_DEBUG is set true. That way you don't need the code i posted above.

  6. oncletom
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Nice to see those technical conversations :-)
    Someone also asked to have an option to force compilation when WP_DEBUG is set to false. I don't like very much making the task easy to decrease performances but maybe I'll add another constant to ease the work if some people need it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic