In light of the 30-day issue that has been closed, I still recently had my generated snippets removed from sites/default/files. Due to a permissions error in how these files were removed, I couldn't just save the configuration form to re-create the files; I was on v1.2. In my case, I'm using inline snippets and was confused as to why my inline snippets stopped working because files were removed: if they're not being served, why would they be generated?

Attached is a patch to change inline snippets to use Drupal's cache instead of files. This patch provides a few perks:

  1. Doesn't have to hit the file system in any way
  2. JIT support is easier to manage should a cache clear occur
  3. Could be used as a backup for sites that have issues creating the snippet files (not part of this patch)
  4. Maintains the benefit of pre-generating the snippets so long as the cache is primed; JIT helps maintain this

I'm willing to iterate on this to get it working. My organization, which hosts a number of Drupal sites, has stuck with v1.0 because of the snippet file generation problems. This patch should help assuage these concerns, as well as decouple file system usage when it's unneeded.

CommentFileSizeAuthor
snippet_cache.patch4.44 KBfractile81
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fractile81 created an issue. See original summary.

solotandem’s picture

Status: Needs review » Postponed (maintainer needs more info)

Based on what you wrote, your confusion would seem to stem from equating inline JS to build-on-the-fly.

The recommended approach of this module (and core, in particular in the 8.x branch) is to include JS snippets as files (i.e., avoid inline JS). Therefore the snippet 'cache' is the file, loaded and inlined if desired. If inline was the preferred approach, then a database cache entry would also make sense. Your patch is reasonable for doing a cache entry, but I am not inclined to implement it for the reason just stated.

Why exactly do you want to inline this JS? Because it has always been done this way for things like analytics? Or something else?

Regarding the 'snippet file generation problems', these were resolved in commits on April 7 (first commit after 1.2 tag) and May 13 (for those needing variable realm support). The former predates this issue by a month; will assume the latter was not relevant to your use case. The generation problem in the 1.2 release in any case only affected module 'updates' not fresh installs (unless realm support was needed) and, even using the 1.2 release, was easily resolved by disable and enable of the module.

solotandem’s picture

Title: Use Cache When Snippet Files Are Disabled » Use cache when snippets are inlined

I think this title is more descriptive of the request.

solotandem’s picture

Status: Postponed (maintainer needs more info) » Fixed

Marking fixed in absence of followup from reporter.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.