Skip to content

The WEB UI cannot loading its JS,CSS files #340

Open

Description

@KiddoLin

I install clockwork to my project, but the WEB UI doesn't work. It can be open in chrome, but can't loading all js and css file. Am I missing something?

"php": "7.2.19"
"laravel/framework": "5.8.29"
"itsgoingd/clockwork": "4.0.5"
composer require itsgoingd/clockwork successfully.

1
2
3

Activity

  1. itsgoingd commented on Jul 25, 2019

    @itsgoingd
    Owner

    Hey, is the 404 error returned by Laravel or your web server?

  2. KiddoLin commented on Jul 26, 2019

    @KiddoLin
    Author

    Well, it has not other errors of Laravel or web server(nginx), only loading failed the 4 files.
    I find that the 4 files is loading failed on Ubuntu and CentOS, but loading successful on Windows.

  3. KiddoLin commented on Jul 26, 2019

    @KiddoLin
    Author

    The nginx run by 'www' user, i try to change all files' owner, and clear cache and route, but the 4 files still loading failed.
    4

    PS: The web app always works.
    5

  4. itsgoingd commented on Jul 26, 2019

    @itsgoingd
    Owner

    I mean, are the 404 response you get a nice Laravel error pages or the basic ones from nginx? That would tell you if the problem is your web server configuration or Laravel/Clockwork.

    If you want to check on what's happening inside Clockwork and dd som stuff:

  5. KiddoLin commented on Jul 26, 2019

    @KiddoLin
    Author

    Oh! The 4 files' 404 response is the basic ones from nginx. It is my nginx default configuration:

      location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
      }
    

    The JS,CSS files was be disabled executing on more web server.Maybe the 4 files' suffix should be changed?

  6. itsgoingd commented on Jul 26, 2019

    @itsgoingd
    Owner

    You will need to add an exception for /__clockwork/*.

    Alternatively you could just copy these files to you public directory, but then it's up to you to keep them up to date, otherwise you'll get stuck on older web UI version. They can change pretty often, that's why we serve them via php in the first place.

  7. KiddoLin commented on Jul 27, 2019

    @KiddoLin
    Author

    OK. I will add an exception to nginx configuration.

    This problem maybe make some novices puzzling, because it is easy to ignore the web server default configurations for someone (like me. Aha...).
    I think it is handy for development if the URI of JS and CSS files can be changed to other formats, like:
    /__clockwork/css/app.360cd53d
    /__clockwork/js/chunk-vendors.cdd797ba

    // Clockwork\Web\Web@resolveAssetPath methods
    
    protected function resolveAssetPath($path)
    {
        $path = $this->getRealPath($path);
        $publicPath = realpath(__DIR__ . '/public');
        $path = realpath("$publicPath/{$path}");
        return strpos($path, $publicPath) === 0 ? $path : false;
    }
    
    protected function getRealPath($path)
    {
        $fileType = explode('/', $path)[0];
        if (in_array($fileType, ['js', 'css'])) {
            $path = "$path.$fileType";
        }
        return $path;
    }
    
  8. williamqian commented on Sep 10, 2019

    @williamqian

    OK. I will add an exception to nginx configuration.

    This problem maybe make some novices puzzling, because it is easy to ignore the web server default configurations for someone (like me. Aha...).
    I think it is handy for development if the URI of JS and CSS files can be changed to other formats, like:
    /__clockwork/css/app.360cd53d
    /__clockwork/js/chunk-vendors.cdd797ba

    // Clockwork\Web\Web@resolveAssetPath methods
    
    protected function resolveAssetPath($path)
    {
        $path = $this->getRealPath($path);
        $publicPath = realpath(__DIR__ . '/public');
        $path = realpath("$publicPath/{$path}");
        return strpos($path, $publicPath) === 0 ? $path : false;
    }
    
    protected function getRealPath($path)
    {
        $fileType = explode('/', $path)[0];
        if (in_array($fileType, ['js', 'css'])) {
            $path = "$path.$fileType";
        }
        return $path;
    }
    

    I have met the same problem as yours, all the js/css are 404 if loaded from the script/link tags,but can be opened in new tab.Could you show me your final nginx cofiguration please?

  9. KiddoLin commented on Sep 11, 2019

    @KiddoLin
    Author

    @williamqian emmm...Finally, I remove the rules about JS and CSS in local/dev/testing ENV.
    6
    Remember to reload your nginx service.

  10. williamqian commented on Sep 11, 2019

    @williamqian

    @williamqian emmm...Finally, I remove the rules about JS and CSS in local/dev/testing ENV.
    6
    Remember to reload your nginx service.

    haha,so did I ,thanks

  11. sachinrcrm commented on Oct 13, 2020

    @sachinrcrm

    I am facing same issue. I am using xampp. How and where should I add exception?

  12. JulianMar commented on Jan 21, 2021

    @JulianMar
    Contributor

    Would be really cool to have a command like php artisan vendor:publish --tag=clockwork-assets.

    This would work for nginx and apache users. Horizon is publishing it's assets like this
    https://laravel.com/docs/8.x/packages#public-assets

  13. bsienn-khan commented on Dec 21, 2023

    @bsienn-khan

    If you must cache assets, then update the rule so it ignores clockwork.

    location ~* ^(?!/clockwork/).*\.(ttf|woff|woff2|css|js|gif|jpe?g|png|svg|webp)(\?[0-9]+)?$ {
            expires 1y;
            add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
    }
    

    This worked for me, though I wanted a seperate rule, but even if the above rules body is empty, the clockwork assets wouldn't return.

  14. added this to the Clockwork 6 milestone on Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions