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

Make deployed_version.txt editor friendly #9338

Closed
wants to merge 1 commit into from

Conversation

AntonEvers
Copy link
Contributor

@AntonEvers AntonEvers commented Apr 21, 2017

Description

In production environments with a CDN for static files it comes in handy that you can force a browser cache refresh by changing the number manually without having to go into maintenance for a full deploy.

If you edit the pub/static/deployed_version.txt with vim, nano or echo '123456789' > pub/static/deployed_version.txt you can unintentionally create a newline at the end of the file.
This will result in:

    var BASE_URL = 'https://magento2.dev/sitemanager/admin/index/index/key/ec38dd3ded42b71db14166d6bcdfc56d4e7d4b7801b9808373ae4b3563b65513/';
    var FORM_KEY = 'dKArsQU6NhimXr6Z';
    var require = {
        "baseUrl": "https://magento2.dev/pub/static/version1492766286
/adminhtml/Magento/backend/en_US"
    };

With that baseUrl all resources using baseUrl will return the 404 page.

Adding a simple trim() here will remove that risk.

Manual testing scenarios

  1. edit the pub/static/deployed_version.txt with vim in a shop that is in production mode
  2. see the admin and frontend throw many js errors

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

In production environments with a CDN for static files it comes in handy that you can force a browser cache refresh by changing the number manually without having to go into maintenance for a full deploy.

If you edit the `pub/static/deployed_version.txt` with vim, nano or `echo '123456789' > pub/static/deployed_version.txt` you can unintentionally create a newline at the end of the file.
This will result in:

```html
    var BASE_URL = 'https://magento2.dev/sitemanager/admin/index/index/key/ec38dd3ded42b71db14166d6bcdfc56d4e7d4b7801b9808373ae4b3563b65513/';
    var FORM_KEY = 'dKArsQU6NhimXr6Z';
    var require = {
        "baseUrl": "https://magento2.dev/pub/static/version1492766286
/adminhtml/Magento/backend/en_US"
    };
```

With that baseUrl all resources using baseUrl will return the 404 page.

Adding a simple `trim()` here will remove that risk.
@ishakhsuvarov
Copy link
Contributor

@ajpevers Isn't it better to add some command/option to the deploy command to refresh the version?

@AntonEvers
Copy link
Contributor Author

@ishakhsuvarov I think a option in the deploy command would be best indeed. An extra command would clutter the bin/magento command list I fear. I'll work on a PR with the extra option. Maybe --refresh-version-only? Would that cover the option well enough? English is not my first language.

@ishakhsuvarov
Copy link
Contributor

@ajpevers Thank you. Looks good to me for now.

@ishakhsuvarov
Copy link
Contributor

@ajpevers Closing this for now due to inactivity. Please reopen and update this PR or create a new one if you wish to continue.
Thanks.

AntonEvers pushed a commit to AntonEvers/magento2 that referenced this pull request Jun 11, 2017
With this option you can quickly force a browser cache refresh or
a CDN cache refresh without having to generate all static content.

This comes in handy especially when you have made no code changes,
but the CDN failed to update it's cache the last time you deployed
or when you have made a manual change in one of the static files
as a hotfix on your deployment server, awaiting a suitable moment
for deployment to finalize it.

This reopens magento#9338.
magento-team pushed a commit that referenced this pull request Jun 15, 2017
…deploy command to refresh the version #9915

 - Merge Pull Request #9915 from ajpevers/magento2:patch-1
 - Merged commits:
   1. 78aba16
   2. 89e0067
   3. 17a44e2
   4. fbc9db3
   5. 4499b6f
   6. cc8e8fd
   7. 9de25f5
magento-team pushed a commit that referenced this pull request Jun 15, 2017
@mengbo123456
Copy link

# now i know why can't linking style ,but i don't know why this?
because install path no version1499055289 folder ,and i add it style work
qq 20170703141604
qq 20170703141841
qq 20170703142510
but i don't know why it can't add version1499055289 folder itself in During the installation process

@AntonEvers
Copy link
Contributor Author

Hello @mengbo123456,

You do not have to create the versionXXXXXXXXXX folder.
Magento also does not have to create the folder.

Please look at this line in the pub/static/.htaccess file: https://github.com/magento/magento2/blob/develop/pub/static/.htaccess#L16

It rewrites urls like https://example.com/pub/static/version1234567890/some/file.jpg to https://example.com/pub/static/some/file.jpg.
So Magento will actually return pub/static/some/file.jpg instead of pub/static/version1234567890/some/file.jpg.

So if one of your files is not found:
in developer mode: rm -r var/view_preprocessed/* pub/static/* var/cache/* var/page_cache/* and reload the page
in production mode: see http://devdocs.magento.com/guides/v2.1/config-guide/cli/config-cli-subcommands-static-view.html#config-cli-subcommands-xlate-dict for Magento 2.1 or http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-static-view.html#config-cli-subcommands-xlate-dict for Magento 2.0

magento-devops-reposync-svc pushed a commit that referenced this pull request Nov 18, 2024
[Hammer][2.4.8-beta2] Platform Health Scope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants