Skip to content
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

Revision compiler revised #2805

Merged
merged 4 commits into from
Apr 29, 2021
Merged

Revision compiler revised #2805

merged 4 commits into from
Apr 29, 2021

Conversation

luceos
Copy link
Member

@luceos luceos commented Apr 22, 2021

Changes proposed in this pull request:

Moving from <asset>-<revision>.<js|css> to <asset>.<js|css>?v=<revision>. As a consequence we no longer need to delete the old file, browsers will automatically pick up that a new file was generated.

Additional changes

  • clean up the revision classes, adding more type hinting (compatible with php 7.3), removing unneeded phpdoc
  • changed the cache differentiator for Less; previously it would use time() causing a recompile every time assets are compiled; but as all sources (string, file) offer their own differentiator and the less compiler only adds import dirs, I've used that as another differentiator. Let me clarify the impact:

For production sites there won't be any change, except that css is compiled less often.
For development environments where import dirs see changes this might be problematic, however this PR also takes this into consideration by allowing the commit() method of the recompiler to get an argument $force (false) to force recompilation when in debug mode.

Reviewers should focus on:

Whether we want to modify the differentator for Less like this.

Screenshot

image

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

  • Related documentation PR: (Remove if irrelevant)
  • Related core extension PRs: (Remove if irrelevant)

- remove deprecated filename for revision method
- reconsider use of cache differentiator and implement something that
prevents recompiling css every single time
@davwheat
Copy link
Member

I love this! :)

Copy link
Member

@askvortsov1 askvortsov1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, including the differentiator changes. Local testing confirms that less is recompiled when changed as expected. Just a slight nitpick, commit assumes debug mode (because it's only called during debug mode). Can we explicitly state this expectation either in a comment, or by renaming to something? forceCommit maybe?

src/Frontend/Content/Assets.php Outdated Show resolved Hide resolved
@luceos
Copy link
Member Author

luceos commented Apr 22, 2021

If the method is named commit, it feels superfluous to name the variable forceCommit. That's a waste of screen width and only makes it unclear as I'd expect something else to be forceable too 🙈

@askvortsov1
Copy link
Member

If the method is named commit

I meant renaming the method in the Assets class to forceCommit

@luceos luceos requested a review from askvortsov1 April 29, 2021 18:01
@askvortsov1 askvortsov1 merged commit e337c10 into master Apr 29, 2021
@askvortsov1 askvortsov1 deleted the dk/asset-revision branch April 29, 2021 20:49
@askvortsov1 askvortsov1 added this to the 1.0 milestone Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants