Review main Merged

77018[FEATURE] Streamline FE/versionNumberInFilename to 'EXT:' resources

Christoph Lehmann CR +2 V +2 Normal +128 −8 updated 06/14/24, 13:04

Commit message

Local resources are currently not "cache-busted", for example, have no version in URL. TypoScript has no possibility to add the cache buster. When replacing them a new filename must be used (which feels little hacky), because web clients may have cached the old file version.

This introduces

1) getText "asset" to cache-bust assets in TypoScript

..  code-block:: typoscript

    page.20 = TEXT
    page.20 {
        value = { asset : EXT:core/Resources/Public/Icons/Extension.svg }
        insertData = 1
    }
    # Result: typo3/sysext/core/Resources/Public/Icons/Extension.svg?1709051481

2) cache-busted assets with the :html:`<f:uri.resource>` ViewHelper

..  code-block:: html

    <f:uri.resource path="EXT:core/Resources/Public/Icons/Extension.svg" />

    Before: typo3/sysext/core/Resources/Public/Icons/Extension.svg
    Now: typo3/sysext/core/Resources/Public/Icons/Extension.svg?1709051481

The ViewHelper argument :html:`useCacheBusting` is enabled by default.

Depending on FE/versionNumberInFilename the cache buster is applied as query string or embedded in the filename.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Josef Glatz +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Benni Mack +2
    • Josef Glatz +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 1

Files 5

Review log 5686

Show 3961 earlier messages
  1. Christoph Lehmann uploaded patch set 1 12/11/22, 22:31

  2. Christoph Lehmann updated the commit message in patch set 2 12/11/22, 22:35

  3. core-ci voted on patch set 1 V -1 12/11/22, 22:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34885

  4. Christoph Lehmann updated the commit message in patch set 3 12/11/22, 22:40

  5. core-ci voted on patch set 2 V -1 12/11/22, 22:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34886

  6. core-ci voted on patch set 3 V -1 12/11/22, 22:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34887

  7. Christoph Lehmann uploaded patch set 4 V -1 12/11/22, 22:55

  8. core-ci voted on patch set 4 V +1 12/11/22, 23:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34888

  9. Christoph Lehmann updated the commit message in patch set 5 V +1 12/12/22, 17:27

  10. core-ci voted on patch set 5 V +1 12/12/22, 17:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34934

  11. Christoph Lehmann updated the commit message in patch set 6 V +1 12/12/22, 17:37

  12. core-ci voted on patch set 6 V +1 12/12/22, 17:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/34935

  13. Benni Mack commented on patch set 6 12/14/22, 20:43

    I actually wondered if we should add the cachebuster to ALL files (CSS, JS, even images from the local storage).
  14. Christoph Lehmann commented on patch set 6 12/15/22, 08:33

    Reply

    I also come to the conclusion, that the cachebuster ist useful for CSS/JS files, but the, lets say normal case, fonts are included in CSS files. There the cachebuster must match the cachebuster added by versionedResourceUri. Not easy to resolve in a "for all working" manner. So the suggested approach by (also) extending getTexts 'file:' with handling `EXT:` would make the feature "round".
  15. Benni Mack commented on patch set 6 02/02/23, 13:08

    how about just "uri:" or "asset:". IMHO it should always be versionnumbered.
  16. Christoph Lehmann rebased onto patch set 7 V +1 04/21/23, 19:19

  17. core-ci voted on patch set 7 V +1 04/21/23, 19:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41063

  18. Christoph Lehmann uploaded patch set 8 V +1 04/21/23, 22:31

  19. core-ci voted on patch set 8 V -1 04/21/23, 22:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41066

  20. Christoph Lehmann uploaded patch set 9 V -1 04/22/23, 09:34

  21. Christoph Lehmann updated the commit message in patch set 10 04/22/23, 09:35

  22. core-ci voted on patch set 9 V +1 04/22/23, 09:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41085

  23. core-ci voted on patch set 10 V +1 04/22/23, 09:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41086

  24. Stefan Bürk updated the commit message in patch set 11 V +1 04/22/23, 15:16

  25. core-ci voted on patch set 11 V +1 04/22/23, 15:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41091

  26. Christoph Lehmann updated the commit message in patch set 12 V +1 04/22/23, 20:57

  27. core-ci voted on patch set 12 V +1 04/22/23, 21:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41092

  28. Oliver Hader commented on patch set 12 04/23/23, 07:26

    ResourceViewHelper.php:95

    I'm not sure whether the version number should be applied explicitly here (e.g. by introducing a new argument to this Fluid view helper)...

    ContentObjectRendererTest.php:1666

    File operations either should be done via `vfs://` or in a functional test

    ContentObjectRendererTest.php:1668

  29. Christoph Lehmann uploaded patch set 13 V +1 04/23/23, 18:44

  30. core-ci voted on patch set 13 V +1 04/23/23, 18:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41102

  31. Oliver Klee commented on patch set 13 04/23/23, 19:17

    ContentObjectRendererTest.php:1666 Reply

    We're moving away from vfsStream in the Core tests. So this needs to go into a functional test.
  32. Christoph Lehmann commented on patch set 13 04/23/23, 19:53

    ResourceViewHelper.php:95 Reply

    From my point of view it works well with CSS/JS and is just missing for other extension resources. Talk in slack?

    ContentObjectRendererTest.php:1666 Reply

    Moved to functional test.

    ContentObjectRendererTest.php:1668 Reply

    Done
  33. Christoph Lehmann rebased onto patch set 14 V +1 06/16/23, 20:47

  34. core-ci voted on patch set 14 V +1 06/16/23, 20:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/42755

  35. Oliver Klee commented on patch set 14 06/16/23, 21:51

    ContentObjectRenderer.php:3933

    `GeneralUtility::getFileAbsFileName` always returns a string. So we should use a type-safe string comparison instead: ```php if ($absoluteFilePath === '') { ```

    ContentObjectRenderer.php:3934

    Please let's always use a more specific exception class. This allows catching a specific exception possible. In this case, maybe a `RuntimeException` would make sense. Also, I propose adding the requested asset path to the exception message to help hunting down problems: ```php throw new RuntimeException('Asset " . $key . " not found', 1670713983); ``` What do you think?

    ContentObjectRendererTest.php:681

    In this case, the test name already contains all information about the expected behavior (which I really like!). So this comment is not needed.

    ContentObjectRendererTest.php:702

    I'm not really comfortable changing/adding files in our normal resources directory, Is there some way we could move this to typo3temp or something similar?

    ContentObjectRendererTest.php:705

    Please always let's make tests as strict as possible. In this case, I'd propose using the stricter `assertSame`: ``` self::assertSame( ```

    ContentObjectRendererTest.php:709

    The `unlink` should go into `tearDown`. Otherwise, if there is a test failure (which PHPUnit implements as an exception), the test is exited, and the `unlink` is never called.
  36. Christoph Lehmann uploaded patch set 15 V +1 07/07/23, 20:56

  37. Christoph Lehmann uploaded patch set 16 07/07/23, 20:58

  38. Christoph Lehmann commented on patch set 15 07/07/23, 20:59

    ContentObjectRenderer.php:3933 Reply

    Done

    ContentObjectRenderer.php:3934 Reply

    Done

    ContentObjectRendererTest.php:681 Reply

    Done

    ContentObjectRendererTest.php:702 Reply

    Its now in typo3temp/var/tests/..

    ContentObjectRendererTest.php:705 Reply

    Done

    ContentObjectRendererTest.php:709 Reply

    Done
  39. core-ci voted on patch set 15 V -1 07/07/23, 21:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43926

  40. core-ci voted on patch set 16 V -1 07/07/23, 21:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43927

  41. Georg Ringer commented on patch set 16 07/08/23, 05:35

    shouldn't this a feature?
  42. Benni Mack commented on patch set 16 01/04/24, 14:50

    can you resolve the merge conflicts and make it a feature? since it adds a new getText property "asset" we need to document this.
  43. Oliver Klee commented on patch set 16 01/04/24, 15:00

    ContentObjectRendererTest.php:84

    Usually, the `parent::tearDown()` call should come last (to be symmetric to the `parent::setUp()` call coming first).
  44. Christoph Lehmann uploaded patch set 17 V -1 01/04/24, 21:00

  45. Christoph Lehmann uploaded patch set 18 01/04/24, 21:01

  46. core-ci voted on patch set 17 V +1 01/04/24, 21:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51117

  47. core-ci voted on patch set 18 V +1 01/04/24, 21:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51118

  48. Christoph Lehmann commented on patch set 18 01/04/24, 21:13

    Reply

    Thanks for the ping. done

    ContentObjectRendererTest.php:84 Reply

    Done
  49. Christoph Lehmann updated the commit message in patch set 19 V +1 01/04/24, 21:58

  50. core-ci voted on patch set 19 V +1 01/04/24, 22:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51119

  51. Chris Müller commented on patch set 19 01/05/24, 06:40

    Feature-99203-StreamlineFEversionNumberInFilenameToEXTResources.rst:22

    Can you give an example of the output? It is "Extension.123456789.svg" (which the needs adjustment in htdocs) or "Extension.svg?123456789". I assume it depends on the configuration? This also explains to the reader what cache-busted means.

    Feature-99203-StreamlineFEversionNumberInFilenameToEXTResources.rst:34

    So, when the FE flag is enabled the resource vh always returns a cache-busted URL?
  52. Christoph Lehmann updated the commit message in patch set 20 V +1 01/17/24, 12:11

  53. Christoph Lehmann commented on patch set 20 01/17/24, 12:15

    Feature-99203-StreamlineFEversionNumberInFilenameToEXTResources.rst:22 Reply

    I added an example. The variant with the cache buster in filename instead as query string is explained in the docs see FE/versionNumberInFilename. For this commit .htaccess adjustments are not nessesary.

    Feature-99203-StreamlineFEversionNumberInFilenameToEXTResources.rst:34 Reply

    Yes. Added it as impact.
  54. core-ci voted on patch set 20 V +1 01/17/24, 12:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51680

  55. Christoph Lehmann uploaded patch set 21 V +1 01/17/24, 12:19

  56. Christoph Lehmann commented on patch set 21 01/17/24, 12:19

    rebased
  57. core-ci voted on patch set 21 V +1 01/17/24, 12:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51681

  58. Christoph Lehmann uploaded patch set 22 V +1 01/29/24, 18:55

  59. Christoph Lehmann commented on patch set 22 01/29/24, 18:56

    Rebased again to resolve merge conflicts.
  60. core-ci voted on patch set 22 V -1 01/29/24, 19:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52458

  61. Chris Müller uploaded patch set 23 V -1 01/30/24, 18:57

  1. core-ci voted on patch set 23 V -1 01/30/24, 19:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52508

  2. Christoph Lehmann uploaded patch set 24 V -1 02/27/24, 18:49

  3. core-ci voted on patch set 24 V -1 02/27/24, 18:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53660

  4. Christoph Lehmann uploaded patch set 25 V -1 02/27/24, 18:55

  5. core-ci voted on patch set 25 V +1 02/27/24, 19:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53661

  6. Chris Müller uploaded patch set 26 V +1 02/28/24, 20:26

  7. Chris Müller uploaded patch set 27 02/28/24, 20:27

  8. core-ci voted on patch set 26 V +1 02/28/24, 20:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53694

  9. core-ci voted on patch set 27 V +1 02/28/24, 20:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53695

  10. Benni Mack commented on patch set 27 03/04/24, 09:48

    ResourceViewHelper.php:100

    OK. I found out that some people might use this result for other further usages. How about we add a new argument "useCacheBusting" which - if not explicitly set, uses the createVersionNumberedFilename(), and can be disabled if necessary by setting <f:resource ... useCacheBusting="false" /> ?
  11. Christoph Lehmann uploaded patch set 28 V +1 03/04/24, 19:42

  12. Christoph Lehmann commented on patch set 28 03/04/24, 19:43

    ResourceViewHelper.php:100 Reply

    Done
  13. core-ci voted on patch set 28 V -1 03/04/24, 19:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53902

  14. Christoph Lehmann rebased onto patch set 29 V -1 03/04/24, 21:44

  15. core-ci voted on patch set 29 V +1 03/04/24, 21:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/53908

  16. Benni Mack commented on patch set 30 V +1 05/03/24, 19:26

    Published edit on patch set 29.
  17. core-ci voted on patch set 30 V +1 05/03/24, 19:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57176

  18. Simon Schaufelberger voted on patch set 30 CR +1 V +1 05/04/24, 00:29

  19. Guido Schmechel commented on patch set 30 05/04/24, 18:10

    typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml Should the description for versionNumberInFilename be adapted slightly? Irrespective of this, the feature has also been successfully tested.
  20. Christoph Lehmann commented on patch set 30 05/06/24, 19:13

    I think, after two years, this one could be merged, or? :-)

    Reply

    What should be added? (Please feel free to do it)
  21. Josef Glatz voted on patch set 30 CR +1 05/07/24, 04:36

  22. Josef Glatz voted on patch set 30 V +1 05/07/24, 05:07

  23. Josef Glatz commented on patch set 30 05/07/24, 05:10

    I find the new getText option "asset" really straightforward (from a naming perspective and usage perspective) The new ViewHelper argument is awesome anyway
  24. Benni Mack voted on patch set 30 CR +2 V +2 06/14/24, 13:04

  25. Benni Mack merged patch set 31 06/14/24, 13:04