balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

No JS and CSS cache busting (filename with hash) in production #6854

Open lucafaggianelli opened 5 years ago

lucafaggianelli commented 5 years ago

Node version: 10.16.3 Sails version (sails): 1.2.3 ORM hook version (sails-hook-orm): 2.1.1 Sockets hook version (sails-hook-sockets): 1.5.5 Organics hook version (sails-hook-organics): 1.0.0 Grunt hook version (sails-hook-grunt): 4.0.1 Uploads hook version (sails-hook-uploads): 0.4.3 DB adapter & version (e.g. sails-mysql@5.55.5): sails-mysql@1.0.1 Skipper adapter & version (e.g. skipper-s3@5.55.5): none


In production I'm having issues with JS and CSS files being cached by the browser, I understood that there's a grunt hash task for appending a hash in the filename, but it's not working and the html in production has a script tag like this:

<script src="/min/production.min.js"></script>

and the file is served from .tmp/public/min, while .tmp/public/hash is empty (from the task file it seems where the JS should be)

Any idea why I don't have the hash in the file name?

sailsbot commented 5 years ago

@lucafaggianelli Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

johnabrams7 commented 5 years ago

Hey @lucafaggianelli, thanks for bringing this to attention.

There may be something missing for this process in the /tasks folder (especially if your sails app began with a much earlier version).

Try making a new sails app and comparing its /tasks with /tasks in your current sails app (diff command is one way) and make sure there’s no difference.

Hope this helps!

lucafaggianelli commented 5 years ago

@johnabrams7 thanks for the hint, I compared the folders with meld and they are the same but for some trailing commas and my pipeline.js has this lines, whereas the newly generated app has only 'dependencies/**/*.js',:

  'dependencies/lodash.js',
  'dependencies/jquery.min.js',
  'dependencies/vue.js',
  'dependencies/vue-router.js',
  'dependencies/**/*.js',

  // First amongst the app-level files, bring in cloud configuration
  'js/cloud.setup.js',

  // Bring in components & utilities before bringing in the rest (i.e. page scripts)
  'js/components/**/*.js',
  'js/utilities/**/*.js',

Now yes, I created the Sails app with an earlier version but I'm sure it was Sails v1+. Do you have other ideas?

whichking commented 5 years ago

Hi, @lucafaggianelli! When you generated the new Sails app, did you select Web App or Empty App when prompted?

lucafaggianelli commented 5 years ago

I selected Web App, the one with auth, login, etc. both for my current app and for the test app I used for comparison

lucafaggianelli commented 5 years ago

@madisonhicks @johnabrams7 this has become a serious trouble for my production website, do you have any idea for a workaround? like appending the package.json version to the js like:

production.min.js?v=1.0.0

how can I do it? any help would be appreciated, thanks for your time!

johnabrams7 commented 5 years ago

@lucafaggianelli We're curious to take a closer look at this; can you provide us a reproduction of the issue in a minimal app repo?

lucafaggianelli commented 5 years ago

@johnabrams7 Well, this is interesting, I just lifted a freshly generated sails app and there is no hash in the JS and CSS file names. This is the same app I used for comparison with my actual app

Here the repo for the repro: https://github.com/lucafaggianelli/sails-cache-busting-repro

At this point I see few paths:

  1. I'm generating a bad app on my laptop
  2. I'm missing some config
whichking commented 5 years ago

Hey, @lucafaggianelli. Thanks for making us aware of this!

Using sails run deploy should solve this for you, since it uses the buildProd task behind the scenes.

If someone has a moment to add this to the relevant docs page, that would be great! Else, we'll try to get on documenting this behavior ASAP.